Deck 2: An Overview of Collections
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/50
Play
Full screen (f)
Deck 2: An Overview of Collections
1
The use of collections is a Python programming requirement, but they are not very useful for working with real-world objects.
False
2
A set is a built-in Python collection type.
True
3
The pop method is used to add items to a Python list.
False
4
Use the & operator to concatenate two collections.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
A line of customers waiting to get into a movie is an example of a hierarchical collection.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
To traverse a collection's items, use the for loop.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
A search operation is usually more efficient on a sorted collection than on an unsorted collection.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
When a shallow copy of a collection is made, only references to the items in the new collection are copied.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
The map, filter, and reduce functions can only be used on list collections.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
Graph collections are organized in a parent/children relationship.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
If you clone an object using the = operator (as in myList=list(yourList) ), the is operator returns True while the == operator returns False.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
When collections share mutable items, a deep copy using a for loop should be used to explicitly clone items before adding them to a new collection.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
A sorted collection must be in a linear structure, ordered by position.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
To determine equality of two collections, use the == operator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
A tuple is an immutable collection type.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
A collection contains at least one item.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
All collections are also iterable objects.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
To be considered equal, two lists must have the same length and the same items in each position, whereas the same sets must simply contain exactly the same items, but in no particular order.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
When using a for loop to iterate over a list, the items are visited in no particular order.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
By default, items in a sorted collection are visited in descending order when using a for loop iterator.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
Which real-world item best represents a linear collection?
A) file system
B) organizational chart
C) stack of bricks
D) table of contents
A) file system
B) organizational chart
C) stack of bricks
D) table of contents
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Python includes two implementations of lists: arrays and linked lists.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Which type of collection is ordered by position?
A) linear
B) hierarchical
C) graph
D) sorted
A) linear
B) hierarchical
C) graph
D) sorted
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
What is the value of c after the following code executes?
A = [ 10, 20, 30 ]
B = [ 40, 50, 60 ]
C = a + b
A) [ 50, 70, 90 ]
B) {[ 10, 20, 30 ], [ 40, 50, 60 ]}
C) [ 10, 20, 30, 40, 50, 60 ]
D) ([ 10, 40 ], [ 20, 50 ], [ 30, 60 ])
A = [ 10, 20, 30 ]
B = [ 40, 50, 60 ]
C = a + b
A) [ 50, 70, 90 ]
B) {[ 10, 20, 30 ], [ 40, 50, 60 ]}
C) [ 10, 20, 30, 40, 50, 60 ]
D) ([ 10, 40 ], [ 20, 50 ], [ 30, 60 ])
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
In computer science, collections are also called objective data types (ODTs).
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
Which statement is true about a sorted collection?
A) must be ordered by position
B) they need not be linear
C) searching is inefficient
D) a box of donuts is an example
A) must be ordered by position
B) they need not be linear
C) searching is inefficient
D) a box of donuts is an example
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
Which of the following is true about Python collections?
A) most can be heterogeneous
B) all are homogeneous
C) they are typically static
D) all are immutable object types
A) most can be heterogeneous
B) all are homogeneous
C) they are typically static
D) all are immutable object types
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
What is the value of aList after the following code is executed?
AList = [ 10, 20, 30 ]
AList.pop()
A) [ 10, 20, 30 ]
B) [ 10,20 ]
C) [ ]
D) [ 20, 30 ]
AList = [ 10, 20, 30 ]
AList.pop()
A) [ 10, 20, 30 ]
B) [ 10,20 ]
C) [ ]
D) [ 20, 30 ]
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
In Python, modules and methods are the smallest units of abstraction, classes are the next in size, and functions are the largest.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
In computer science, abstraction is used for ignoring or hiding details that are nonessential.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
What is the value of myObject after the following code executes?
YourObject = "Hi"
MyObject = tuple(yourObject)
A) ('H', 'i')
B) [ "H", "i" ]
C) (Hi)
D) ("Hi")
YourObject = "Hi"
MyObject = tuple(yourObject)
A) ('H', 'i')
B) [ "H", "i" ]
C) (Hi)
D) ("Hi")
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following is a special case of type conversion, where the two collections are of the same type?
A) replacing
B) copying
C) duplicating
D) cloning
A) replacing
B) copying
C) duplicating
D) cloning
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following is an unordered collection?
A) string
B) stack
C) dictionary
D) queue
A) string
B) stack
C) dictionary
D) queue
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Without abstraction, you would need to consider all aspects of a software system simultaneously.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Which real-world item best represents a hierarchical collection?
A) a queue of customers
B) wiring diagrams
C) a box of legos
D) a family tree
A) a queue of customers
B) wiring diagrams
C) a box of legos
D) a family tree
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
Which Python function returns the total number of items in a collection?
A) sizeof
B) len
C) count
D) total
A) sizeof
B) len
C) count
D) total
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Which object type is immutable?
A) list
B) set
C) dict
D) tuple
A) list
B) set
C) dict
D) tuple
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
What is the value of aList after the following code is executed?
AList = [ 1, 2, 3 ]
AList.remove(2)
A) [ 1, 2 ]
B) [ 1, 3 ]
C) [ 3 ]
D) [ 1 ]
AList = [ 1, 2, 3 ]
AList.remove(2)
A) [ 1, 2 ]
B) [ 1, 3 ]
C) [ 3 ]
D) [ 1 ]
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
What is a group of zero or more items that can be operated on as a unit?
A) grouping
B) collection
C) array
D) organization
A) grouping
B) collection
C) array
D) organization
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Which operator can you use to test for item membership in a collection?
A) in
B) ==
C) @
D) is
A) in
B) ==
C) @
D) is
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
In what order are dictionary items visited during an iteration?
A) the order in which they were added
B) ascending, by key value
C) descending, by item value
D) no particular order
A) the order in which they were added
B) ascending, by key value
C) descending, by item value
D) no particular order
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
What can a programmer do to prevent side effects from cloning mutable objects?
A) create a deep copy using a for loop
B) create a shallow copy using a type conversion
C) create a deep copy using a type conversion
D) use the assignment operator in stead of a type conversion
A) create a deep copy using a for loop
B) create a shallow copy using a type conversion
C) create a deep copy using a type conversion
D) use the assignment operator in stead of a type conversion
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
When a for loop is used to iterate over a collection, which statement is true?
A) list items are visited from last to first
B) items in a list are visited in a random order
C) items in a sorted collection are visited in ascending order
D) items in a dictionary are visited in descending order
A) list items are visited from last to first
B) items in a list are visited in a random order
C) items in a sorted collection are visited in ascending order
D) items in a dictionary are visited in descending order
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
Which operator is used to obtain a string representation of a collection?
A) len
B) char
C) str
D) in
A) len
B) char
C) str
D) in
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
Which of the following lists Python units of abstraction from smallest to largest?
A) classes, methods, functions, modules
B) functions, methods, classes, modules
C) modules, functions, methods, classes
D) modules, classes, methods, function
A) classes, methods, functions, modules
B) functions, methods, classes, modules
C) modules, functions, methods, classes
D) modules, classes, methods, function
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
In which type of collection does each item have many predecessors and successors, called neighbors?
A) linear
B) hierarchical
C) graph
D) unordered
A) linear
B) hierarchical
C) graph
D) unordered
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
What is the value of newObject after the following code executes?
NewObject = tuple("Hello")
A) ('H', 'e', 'l', 'l', 'o')
B) [ "Hello" ]
C) ("Hello")
D) [ 'H', 'e', 'l', 'l', 'o' ]
NewObject = tuple("Hello")
A) ('H', 'e', 'l', 'l', 'o')
B) [ "Hello" ]
C) ("Hello")
D) [ 'H', 'e', 'l', 'l', 'o' ]
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
What is the value of newList after the following code executes?
NewList = list(range(9, 0, -3))
A) [ 8, 5, 2 ]
B) [ 9, 6, 3, 0 ]
C) [ 9, 6, 3 ]
D) [ ]
NewList = list(range(9, 0, -3))
A) [ 8, 5, 2 ]
B) [ 9, 6, 3, 0 ]
C) [ 9, 6, 3 ]
D) [ ]
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
What is the value of r after the following code executes?
MySet = {2, 3, 5, 7, 11}
YourSet = {5, 7, 2, 11, 3}
R = yourSet == mySet
A) {5, 7, 2, 11, 3}
B) True
C) False
D) 0
MySet = {2, 3, 5, 7, 11}
YourSet = {5, 7, 2, 11, 3}
R = yourSet == mySet
A) {5, 7, 2, 11, 3}
B) True
C) False
D) 0
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
What is the value of r after the following code executes?
MyList = [ 2, 3, 5, 7, 11 ]
YourList = list(myList)
R = yourList is myList
A) [ 2, 3, 5, 7, 11 ]
B) True
C) None
D) False
MyList = [ 2, 3, 5, 7, 11 ]
YourList = list(myList)
R = yourList is myList
A) [ 2, 3, 5, 7, 11 ]
B) True
C) None
D) False
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck