Deck 4: Lists
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/85
Play
Full screen (f)
Deck 4: Lists
1
A list is an ordered, linear data structure in which each element in the list is accessed by its location in the list.
True
2
Zero-based indexing means that the index value of a list always starts with 0.
True
3
The typical list operations retrieve, update, insert, delete and append each need to be provided with an index value.
False
4
List traversal is the process of accessing, one-by-one, each element in a list.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
5
List traversal always begins with the first element of a list.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
6
What would be the range of index values for a list of 10 elements?
A) 0 - 9
B) 1 - 10
C) 0 - 10
A) 0 - 9
B) 1 - 10
C) 0 - 10
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following typical list operations does not need to be provided an index value?
A) append
B) insert
C) delete
A) append
B) insert
C) delete
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
8
The process of accessing each element of a list, one-by-one, is referred to as
A) list stepping
B) list traversal
C) linear access
A) list stepping
B) list traversal
C) linear access
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
9
Match the descriptions with their terms:
-removes the item in a list a the specified index value
A) retrieve
B) update
C) insert
D) delete
E) append
-removes the item in a list a the specified index value
A) retrieve
B) update
C) insert
D) delete
E) append
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
10
Match the descriptions with their terms:
-adds at new value in a list at the specified index value
A) retrieve
B) update
C) insert
D) delete
E) append
-adds at new value in a list at the specified index value
A) retrieve
B) update
C) insert
D) delete
E) append
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
11
Match the descriptions with their terms:
-gets the value in the list at the specified index value
A) retrieve
B) update
C) insert
D) delete
E) append
-gets the value in the list at the specified index value
A) retrieve
B) update
C) insert
D) delete
E) append
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
12
Match the descriptions with their terms:
-adds a provided value to the end of the list
A) retrieve
B) update
C) insert
D) delete
E) append
-adds a provided value to the end of the list
A) retrieve
B) update
C) insert
D) delete
E) append
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
13
Match the descriptions with their terms:
-replaces the value at the specified index location and a provided value
A) retrieve
B) update
C) insert
D) delete
E) append
-replaces the value at the specified index location and a provided value
A) retrieve
B) update
C) insert
D) delete
E) append
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
14
A linear data structure is simply referred to as a _______.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
15
Lists in which the first index value is always 0 is referred to as _______________________.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
16
Five basic operations performed on lists are __________, ___________, ___________,______________, and _____________.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
17
The process of accessing each element of a list, one-by-one, is referred to as___________________.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
18
Lists must contain at least one element in Python.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
19
Lists in Python use zero-based indexing.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
20
Lists in Python as mutable, which means that the contents of the list may be altered.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
21
An empty list in Python is denote as [''].
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
22
In Python, square brackets are used to both create a list and access its individual elements.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
23
Tuples are the same as lists in Python, with the exception that they are immutable.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
24
An empty tuple is denote as ( ) in Python.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
25
Of the basic list operations of retrieve, update, insert, delete and append, only the append operation can be used on tuples.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
26
The + operator is used to concatenate two lists or two strings into one.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
27
Because lists can contain elements of any type, they can also contain lists as their elements, allowing for the creation of arbitrarily complex data structures.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
28
Strings, tuples and strings are collectively referred to as sequences in Python, and therefore the elements of each type can be accessed by index value.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
29
The slice operation removes an index range of values from a list.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following is not a characteristic of lists in Python?
A) mutable
B) variable length
C) may contain mixed-type elements
D) nonlinear
A) mutable
B) variable length
C) may contain mixed-type elements
D) nonlinear
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is the proper way to denote an empty list in Python?
A) ['']
B) [ ]
C) ['empty']
D) all of the above
A) ['']
B) [ ]
C) ['empty']
D) all of the above
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following is the correct way to access the fourth element of a list named lst?
A) lst[4]
B) lst[3]
C) lst['3']
D) lst['4']
A) lst[4]
B) lst[3]
C) lst['3']
D) lst['4']
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
33
Square brackets are used with lists in Python to
A) access a particular element of a list
B) to create a list with specified elements
C) to create an empty list
D) all of the above
A) access a particular element of a list
B) to create a list with specified elements
C) to create an empty list
D) all of the above
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following is not a valid list in Python?
A) [85, 'sunny', 'June 5']
B) [10; 20; 30]
C) ['one', 'two', 'three']
D) all of the above
A) [85, 'sunny', 'June 5']
B) [10; 20; 30]
C) ['one', 'two', 'three']
D) all of the above
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
35
For lst = [10, 20, 30, 40, 50], what value is accessed by list[3]?
A) 30
B) 40
C) '30'
D) '40'
A) 30
B) 40
C) '30'
D) '40'
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
36
What should the value of k be for lst[k] to access the tenth element of list lst?
A) 9
B) 9.0
C) '9'
D) All of the above
A) 9
B) 9.0
C) '9'
D) All of the above
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
37
For lst = [10, 20, 30, 40, 50], what value is the value of lst after del lst[3] is performed?
A) [10, 20, 30]
B) [30, 40, 50]
C) [10, 20, 40, 50]
D) [10, 20, 30, 50]
A) [10, 20, 30]
B) [30, 40, 50]
C) [10, 20, 40, 50]
D) [10, 20, 30, 50]
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
38
For lst = [10, 20, 30, 40, 50], what value is the value of lst after lst.append(0) is performed?
A) [0, 10, 20, 30, 40, 50]
B) [10, 20, 30, 40, 50, 0]
C) [0]
D) [ ]
A) [0, 10, 20, 30, 40, 50]
B) [10, 20, 30, 40, 50, 0]
C) [0]
D) [ ]
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
39
For lst = [10, 20, 30, 40, 50], what is the value of lst after lst.insert(3, 0) is performed?
A) [10, 20, 0, 30, 0, 40, 50]
B) [10, 20, 30, 0, 40, 50]
C) [10, 20, 30, 40, 0, 50]
D) [10, 20, 30, 40, 50, 0]
A) [10, 20, 0, 30, 0, 40, 50]
B) [10, 20, 30, 0, 40, 50]
C) [10, 20, 30, 40, 0, 50]
D) [10, 20, 30, 40, 50, 0]
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
40
For lst = [10, 20, 30, 40, 50], what is the resulting value of lst[2:4]?
A) [20, 30]
B) [20, 30, 40]
C) [30, 40]
D) [30, 40, 50]
A) [20, 30]
B) [20, 30, 40]
C) [30, 40]
D) [30, 40, 50]
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
41
For some list lst, what will be the result of the execution of the instruction lst.insert(1, 3)?
A) insert the value 1 at the location of the third element in the list
B) insert the value 1 at the location of the fourth element in the list
C) replace the third element in the list with the value 1
D) replace the fourth element in the list with the value 1
A) insert the value 1 at the location of the third element in the list
B) insert the value 1 at the location of the fourth element in the list
C) replace the third element in the list with the value 1
D) replace the fourth element in the list with the value 1
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
42
Which of the following is the correct notation for a tuple of only one element?
A) (10,)
B) (10)
C) (,10,)
D) All of the above
A) (10,)
B) (10)
C) (,10,)
D) All of the above
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following operations cannot be used with tuples?
A) len
B) slice
C) del
D) concatenation
A) len
B) slice
C) del
D) concatenation
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
44
For nested list lst = [ [10, 20, 30], [40, 50, 60] ], which of the following is the correct means of assessing the element with the value 40?
A) lst[0][0]
B) lst[0][1]
C) lst[1][0]
D) lst[2][1]
A) lst[0][0]
B) lst[0][1]
C) lst[1][0]
D) lst[2][1]
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
45
In Python, all lists are indexed starting with an index value of 0. This is referred to as _______________________.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
46
In Python, ____________ are the same as lists, except that their contents cannot be altered.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
47
The ___ operator symbol is used to represent the concatenation of two lists or strings.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
48
An operator symbol (such as +) that is used to denote to different possible operations (arithmetic addition and concatenation) is referred to as an ________________ operator.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
49
Lists, tuples and strings are collectively referred to as _______________ in Python.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
50
The ______________ operation in Python can be used to obtain a sublist (ubstring) or a given list (string).
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
51
Give Python code that replaces the value 25 in list lst = [10, 20, 25, 40] with the value 40.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
52
Give Python code that inserts the value 35 in lst = [10, 20, 25, 40] so that the values in the list remain in numerical order.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
53
Give Python code that adds to the (empty) list lst = [ ] the values 10, 20, 30 such that lst = [10, 20, 30]
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
54
Give Python code to determine if two lists, lstA and lstB, both of length 4, have the same values (e.g., are equal), setting Boolean value True or False to equal_lists, accordingly.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
55
Give Python code that prompts the user for a series of positive numbers, and stores them in a list named num_list in the order that they are entered.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
56
For statements are used for the construction of definite loops.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
57
For loops can be used with all sequence types, except for strings.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
58
The built-in range function in Python is used for generating a sequence of integers.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
59
When iterating over a list, a for loop may be used to either iterate over the list values, or the index values of the list.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
60
In for loops, the loop variable always serves as an index variable.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
61
The for loop Is always the best iterative control structure to use when traversing over indexed data structures in Python.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
62
Although while loops can be nested, for loops cannot because of their use of a loop variable.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
63
Which of the following best describes the kind of control flow that a for loop provides?
A) definite loop
B) indefinite loop
C) terminating loop
D) finite loop
A) definite loop
B) indefinite loop
C) terminating loop
D) finite loop
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
64
Examine the following Python code,
NumList = [1, 4, 6, 8, 10, 3, 12]
For k in range(0, len(numList)):
Print(numList[k])
How many times does the above loop iterate?
A) 0
B) 6
C) 7
D) 8
NumList = [1, 4, 6, 8, 10, 3, 12]
For k in range(0, len(numList)):
Print(numList[k])
How many times does the above loop iterate?
A) 0
B) 6
C) 7
D) 8
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
65
Examine the following Python code,
NumList = [1, 4, 6, 8, 10, 3, 12]
For k in numList:
Print(k)
How many times does the above loop iterate?
A) 0
B) 6
C) 7
D) 8
NumList = [1, 4, 6, 8, 10, 3, 12]
For k in numList:
Print(k)
How many times does the above loop iterate?
A) 0
B) 6
C) 7
D) 8
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
66
Examine the following Python code, 
A) the first only
B) the first and second only
C) the second and third only
D) each of the loops

A) the first only
B) the first and second only
C) the second and third only
D) each of the loops
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
67
The for statement is used to construct __________ loops.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
68
For statement can be applied both lists and tuples, as well as _____________.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
69
The built-in ________ function in Python can be used for generating a sequence of integers.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
70
When iterating over a list by use of a for loop, the loop variable may range over the ____________ of the list, or the ___________ values.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
71
Give Python code to add up all the elements in a list of integers named nums, and displays the result.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
72
Give Python code that displays how many even elements there are in a list of integers named nums.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
73
Give Python code that determines the average of only the positive integers in a list of positive and negative integers named nums.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
74
For fruit = ' banana', what is displayed by the following Python code?
for k in range(0, len(fruit), 2):
print(fruit[k], end='')
for k in range(0, len(fruit), 2):
print(fruit[k], end='')
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
75
Give Python code that, for two lists of integers (of the same length) named nums1 and num2, creates a third list named nums3 containing the sum of the corresponding numbers in each list, as demonstrated below.
num1 [1, 2, 3, 4] num2[10, 20, 30, 40] num3[11, 22, 33, 44]
num1 [1, 2, 3, 4] num2[10, 20, 30, 40] num3[11, 22, 33, 44]
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
76
When a variable is assigned to another variable holding a list, each variable ends up referring to the same instance of the list in memory.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
77
List comprehensions are an alternate means of generating the same sequences that can be generated using the built-in range function in Python.
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
78
Examine the following lines of Python code:
Lst1 = [1, 2, 3, 4]
Lst2 = [1, 2, 3, 4]
Lst1 == lst2
What will the last line return?
A) True
B) False
C) an error
Lst1 = [1, 2, 3, 4]
Lst2 = [1, 2, 3, 4]
Lst1 == lst2
What will the last line return?
A) True
B) False
C) an error
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
79
Examine the following lines of Python code:
Lst1 = [1, 2, 3, 4]
Lst2 = lst1
Lst1 == lst2
What will the last line return?
A) True
B) False
C) an error
Lst1 = [1, 2, 3, 4]
Lst2 = lst1
Lst1 == lst2
What will the last line return?
A) True
B) False
C) an error
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck
80
Examine the following lines of Python code:
Lst1 = [1, 2, 3, 4]
Lst2 = lst1
Lst1 [0] = 10
Lst1 == lst2
What will the last line return?
A) True
B) False
C) an error
Lst1 = [1, 2, 3, 4]
Lst2 = lst1
Lst1 [0] = 10
Lst1 == lst2
What will the last line return?
A) True
B) False
C) an error
Unlock Deck
Unlock for access to all 85 flashcards in this deck.
Unlock Deck
k this deck