10. Lists - 37 Questions


10. Lists

10. Lists

37 Questions
Created by Y. Daniel Liang - http://www.cs.armstrong.edu/liang/index.html
Free
The list type is a container that holds a number of other objects, in a given order. The list type implements the sequence protocol, and also allows you to add and remove objects from the sequence. This quiz aims to test the knowledge of Lists in Python programming language.
  1. __________ creates a list.



    list1 = list()
    list1 = []
    list1 = list([12, 4, 4])
    All of above

    View Answer | Discuss in forum
  2. What is list("abcd")?



    ['a', 'b', 'c', 'd']
    ['ab']
    ['cd']
    ['abcd']

    View Answer | Discuss in forum
  3. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is len(list1)? 



    5
    6
    7
    8

    View Answer | Discuss in forum
  4. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is max(list1)? 



    5
    6
    8
    25

    View Answer | Discuss in forum
  5. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is min(list1)?



    1
    4
    5
    8

    View Answer | Discuss in forum
  6. Suppose list1 is [1, 3, 2], what is sum(list1)? 



    5
    4
    6
    error

    View Answer | Discuss in forum
  7. To shuffle list1, use _______.



    list1.shuffle()
    shuffle(list1)
    random.shuffle(list1)
    random.shuffleList(list1)

    View Answer | Discuss in forum
  8. Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], Which of the following is correct?



    print(list1[0])
    print(list1[:2])
    print(list1[:-2])
    All of above

    View Answer | Discuss in forum
  9. Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is list1[-1]?



    3
    5
    1
    0

    View Answer | Discuss in forum
  10. Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], What is list1[:-1]?



    0
    [1, 3, 2, 4, 5, 2, 1]
    [1, 3, 2, 4, 5, 2]
    [1, 3, 2, 4, 5, 2, 1, 0]

    View Answer | Discuss in forum
  11. Suppose list1 is [1, 3, 2], What is list1 * 2?



    [2, 6, 4]
    [1, 3, 2, 1, 3]
    [1, 3, 2, 1, 3, 2]
    [1, 3, 2, 3, 2, 1]

    View Answer | Discuss in forum
  12. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is ________



    [0, 1, 2, 3]
    [0, 1, 2, 3, 4]
    [0.0, 0.5, 1.0, 1.5]
    [0.0, 0.5, 1.0, 1.5, 2.0]

    View Answer | Discuss in forum
  13. list1 = [11, 2, 23] and list2 = [11, 2, 2], list1 < list2 is ________



    True
    False
    Not defined
    Error

    View Answer | Discuss in forum
  14. list1 = [11, 2, 23] and list2 = [2, 11, 23], list1 == list2 is ________



    True
    False
    Not defined
    Error

    View Answer | Discuss in forum
  15. To add 5 to the end of list1, use _______. 



    list1.add(5)
    list1.append(5)
    list1.addLast(5)
    list1.addEnd(5)

    View Answer | Discuss in forum
  16. To insert 5 to the third position in list1, use _______. 



    list1.insert(3, 5)
    list1.insert(2, 5)
    list1.add(3, 5)
    list1.append(3, 5)

    View Answer | Discuss in forum
  17. To remove string "red" from list1, use _______. 



    list1.remove("red")
    list1.remove(red)
    list1.removeAll("red")
    list1.removeOne("red")

    View Answer | Discuss in forum
  18. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.index(5)?



    0
    4
    1
    2

    View Answer | Discuss in forum
  19. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.count(5)?



    0
    4
    1
    2

    View Answer | Discuss in forum
  20. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.sort()?



    [3, 4, 5, 20, 5, 25, 1, 3]
    [1, 3, 3, 4, 5, 5, 20, 25]
    [25, 20, 5, 5, 4, 3, 3, 1]
    [1, 3, 4, 5, 20, 5, 25, 3]

    View Answer | Discuss in forum
  21. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()? 



    [3, 4, 5, 20, 5, 25, 1, 3]
    [1, 3, 3, 4, 5, 5, 20, 25]
    [25, 20, 5, 5, 4, 3, 3, 1]
    [3, 1, 25, 5, 20, 5, 4, 3]

    View Answer | Discuss in forum
  22. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.extend([34, 5])?



    [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]
    [1, 3, 3, 4, 5, 5, 20, 25, 34, 5]
    [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
    [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]

    View Answer | Discuss in forum
  23. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop(1)?



    [3, 4, 5, 20, 5, 25, 1, 3]
    [1, 3, 3, 4, 5, 5, 20, 25]
    [3, 5, 20, 5, 25, 1, 3]
    [1, 3, 4, 5, 20, 5, 25]

    View Answer | Discuss in forum
  24. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.pop()?



    [3, 4, 5, 20, 5, 25, 1]
    [1, 3, 3, 4, 5, 5, 20, 25]
    [3, 5, 20, 5, 25, 1, 3]
    [1, 3, 4, 5, 20, 5, 25]

    View Answer | Discuss in forum
  25. "Welcome to Python".split() is ________



    ["Welcome", "to", "Python"]
    ("Welcome", "to", "Python")
    {"Welcome", "to", "Python"}
    "Welcome", "to", "Python"

    View Answer | Discuss in forum
  26. What is list("a#b#c#d".split('#')?



    ['a', 'b', 'c', 'd']
    ['a b c d']
    ['a#b#c#d']
    ['abcd']

    View Answer | Discuss in forum
  27. What will be displayed by the following code?

    myList = [1, 5, 5, 5, 5, 1]
    max = myList[0]
    indexOfMax = 0
    for i in range(1, len(myList)):
        if myList[i] > max:
            max = myList[i]
            indexOfMax = i

    print(indexOfMax)



    0
    1
    2
    3

    View Answer | Discuss in forum
  28. What will be displayed by the following code?

    myList = [1, 2, 3, 4, 5, 6]
    for i in range(1, 6):
        myList[i - 1] = myList[i]

    for i in range(0, 6): 
        print(myList[i], end = " ")



    2 3 4 5 6 1
    6 1 2 3 4 5
    2 3 4 5 6 6
    1 1 2 3 4 5

    View Answer | Discuss in forum
  29. What will be displayed by the following code?

    list1 = [13]
    list2 = list1
    list1[0] = 4
    print(list2)



    [1, 3]
    [4, 3]
    [1, 4]
    [1, 3, 4]

    View Answer | Discuss in forum
  30. What will be displayed by the following code?

    def f(values):
        values[0] = 44

    v = [123]
    f(v)
    print(v)



    [1, 44]
    [1, 2, 3, 44]
    [44, 2, 3]
    [1, 2, 3]

    View Answer | Discuss in forum
  31. What will be displayed by the following code?

    def f(value, values):
        v = 1
        values[0] = 44

    t = 3
    v = [1, 2, 3]
    f(t, v)
    print(t, v[0])



    1 1
    1 44
    3 1
    3 44

    View Answer | Discuss in forum
  32. What will be displayed by the following code?

    def f(i, values = []):
        values.append(i)
        return values

    f(1)
    f(2)
    v = f(3)
    print(v)



    [1] [2] [3]
    [1] [1, 2] [1, 2, 3]
    [1, 2, 3]
    1 2 3

    View Answer | Discuss in forum
  33. For the binarySearch function in Section 10.10.2, what is low and high after the first iteration of the while loop when invoking binarySearch([1, 4, 6, 8, 10, 15, 20], 11)?



    low is 0 and high is 6
    low is 0 and high is 3
    low is 3 and high is 6
    low is 4 and high is 6

    View Answer | Discuss in forum
  34. If a key is not in the list, the binarySearch function returns _________.



    insertion point
    insertion point - 1
    -(insertion point + 1)
    -insertion point

    View Answer | Discuss in forum
  35. If the binary search function returns -4, where should the key be inserted if you wish to insert the key into the list?



    at index 3
    at index 4
    at index 5
    at index 6

    View Answer | Discuss in forum
  36. Use the selectionSort function presented in this section to answer this question. Assume lst is [3.1, 3.1, 2.5, 6.4, 2.1], what is the content of list after the first iteration of the outer loop in the function?



    2.1, 3.1, 2.5, 6.4, 3.1
    2.5, 3.1, 3.1, 6.4, 2.1
    2.1, 2.5, 3.1, 3.1, 6.4
    3.1, 3.1, 2.5, 2.1, 6.4

    View Answer | Discuss in forum
  37. Use the selectionSort function presented in this section to answer this question. What is list1 after executing the following statements?

    list1 = [3.13.12.56.4]
    selectionSort(list1)



    list1 is 3.1, 3.1, 2.5, 6.4
    list1 is 2.5 3.1, 3.1, 6.4
    list1 is 6.4, 3.1, 3.1, 2.5
    list1 is 3.1, 2.5, 3.1, 6.4

    View Answer | Discuss in forum