Deck 5: Lists and Dictionaries

Full screen (f)
exit full mode
Question
Although a list's elements are always ordered by position, it is possible to impose a natural ordering on them as well.
Use Space or
up arrow
down arrow
to flip the card.
Question
A function can be defined in a Python shell, but it is more convenient to define it in an IDLE window, where it can be saved to a file.
Question
An Identity function usually tests its argument for the presence or absence of some property.
Question
In scripts that include the definitions of several cooperating functions, it is often useful to define a special function named init that serves as the entry point for the script.
Question
Anytime you foresee using a list whose structure will not change, you can, and should, use a tuple instead.
Question
When replacing an element in a list, the subscript is used to reference the target of the assignment statement, which is not the list but an element's position within it.
Question
A list is a sequence of data values called indexes.
Question
To prevent aliasing, a new object can be created and the contents of the original can be copied to it.
Question
The definition of the main function and the other function definitions can appear in no particular order in the script, as long as main is called at the very end of the script.
Question
A list is immutable.
Question
Each item in a list has a unique index that specifies its position.
Question
A Python dictionary is written as a sequence of key/value pairs separated by commas. These pairs are sometimes called indexes.
Question
The index of the last item in a list is the length of the list.
Question
The == operator returns True if the variables are aliases for the same object. Unfortunately, == returns False if the contents of two different objects are the same.
Question
The is operator has no way of distinguishing between object identity and structural equivalence.
Question
The index of the first item in a list is 1.
Question
The main function usually expects no arguments and returns no value.
Question
Lists of integers can be built using the range function.
Question
The list method ascending mutates a list by arranging its elements in ascending order.
Question
The print function strips the quotation marks from a string, but it does not alter the look of a list.
Question
When a Python script is running as a standalone program, what will the __name__ variable be set to?

A) The variable will hold the name of the script itself.
B) The variable will be set to "__main__".
C) The variable will be set to "standalone".
D) The variable will be set to "None".
Question
What operator should you utilize if you wish to test for object identity between two objects?

A) ==
B) is
C) !=
D) @!
Question
A lookup table is a type of dictionary.
Question
In order to create a docstring for a defined function, where should the docstring be?

A) The docstring should be just before the declaration of def.
B) The docstring should be placed at the end of the execution block for the function.
C) The docstring should be the next indented line after the def statement.
D) The docstring should be placed at the end of the function, before the return statement.
Question
What are the two arguments expected by the get method for a dictionary object? (Choose two.)

A) A possible key.
B) An index position.
C) A list of keys.
D) A default value.
Question
What statement regarding the use of lists is accurate?

A) The individual elements within a list are immutable, in that the values cannot be changed.
B) Two lists cannot be concatenated together, without the creation of a third list.
C) A list can be sliced into sublists.
D) When a list is evaluated, the elements are not evaluated.
Question
If pop is used with just one argument and this key is absent from the dictionary, Python raises an error.
Question
In a dictionary, a -> separates a key and its value.
Question
What statement accurately describes what a mutator is in the Python language?

A) A mutator is a method that converts immutable data into mutable data.
B) A mutator is a method used to encrypt text.
C) A mutator is a method that is devoted entirely to the modification of the internal state of an object.
D) A mutator is a method that changes the structure of a block of Python code.
Question
In a Python dictionary, an association is formed between what two components of the dictionary? (Choose two.)

A) lists
B) keys
C) values
D) indexes
Question
What method should you utilize to add the elements of list2 onto the end of list1?

A) list1.extend(list2)
B) list1.append(list2)
C) list2.append(list1)
D) list2.extend(list1)
Question
You add a new key/value pair to a dictionary by using the subscript operator [].
Question
What statement accurately describes the use of a parameter in Python?

A) A parameter is the name used in the function definition for an argument that is passed to the function when it is called.
B) A parameter is the name used for a function that is then referenced by other parts of the program.
C) A parameter is the name used for data that is returned from the execution of a function.
D) A parameter is the name given to an acceptable range of values that are output from a program.
Question
The median of a list of values is the value that occurs most frequently.
Question
You are designing a script that may be imported as a module in other scripts. What variable can you use to check whether the script has been imported as a module, or is running as the main script?

A) __parent__
B) __name__
C) __operating_mode__
D) __status__
Question
What list method should you use in order to remove and return the element at the end of the list named "books"?

A) books.get()
B) books.pop()
C) books.fetch()
D) books.pull()
Question
What happens if you attempt to pop a key from a dictionary and the key does not exist, and you specified no default return?

A) The pop will return a None value.
B) The pop will return a value of 0.
C) The pop will return a value of False.
D) An error will be raised.
Question
What is the return value for a function that has no return statement defined?

A) The function will return a value of False.
B) The function will return a value of True, provided there are no errors.
C) The function will return a NULL value.
D) The function will return a special value of None.
Question
What statement accurately describes the difference between a list and a tuple?

A) A list is immutable, while a tuple is not.
B) A list is created with elements in parentheses, while a tuple is created with square brackets.
C) A tuple's contents cannot be changed.
D) A tuple can only hold integer and float data.
Question
A list is a sequence of data values known by either of what two terms? (Choose two.)

A) cards
B) instances
C) items
D) elements
Question
When creating a list of items whose structure will not change, what should you ideally use to contain the values?

A) lists
B) tuples
C) dictionaries
D) strings
Question
In computer science, what are two names that are used to describe data structures organized by association? (Choose two.)

A) matrices
B) tables
C) association lists
D) family trees
Question
What happens if you use the following statement to sort a list of numbers called numbers? numbers = numbers.sort()

A) numbers is a value of None
B) The list is now ordered in ascending order.
C) The list is now ordered in descending order.
D) The numbers variable becomes a reference to a sorted list.
Question
When declaring a tuple, you enclose the tuple's elements in what two characters?

A) []
B) ()
C) {}
D) "Y"
Question
What dictionary method can be utilized to access the entries in a dictionary variable with a name of parts?

A) parts.list()
B) parts.items()
C) parts.print()
D) parts.show()
Question
What statement correctly defines what a median is?

A) A median is the minimum value that is smaller than all other values in a set.
B) A median is the maximum value that is greater than all other values in a set.
C) A median is the value that is less than half the numbers in a set and greater than the other half.
D) A median is the sum of all odd values in a set.
Question
You are creating a Python script that will make use of user input contact names and their associated phone numbers. What would be ideal for storing and accessing these associated values?

A) lists
B) tuples
C) dictionaries
D) strings
Question
If you use the range method with a single parameter of 50, what will be the range of integers included in the returned list?

A) 0 through 50
B) 0 through 49
C) 1 through 50
D) 1 through 49
Question
Which of the following assigns a dictionary list of keys and values to the variable named persons?

A) persons = ["Sam":"CEO", "Julie":"President"]
B) persons = ("Sam":"CEO", "Julie":"President")
C) persons = {"Sam":"CEO", "Julie":"President"}
D) persons = {["Sam", "CEO"], ["Julie", "President"]}
Question
What dictionary operation can you use to remove all the keys within the dictionary named contacts?

A) contacts.delete()
B) contacts.remove()
C) contacts.clear()
D) contacts.dump()
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 5: Lists and Dictionaries
1
Although a list's elements are always ordered by position, it is possible to impose a natural ordering on them as well.
True
2
A function can be defined in a Python shell, but it is more convenient to define it in an IDLE window, where it can be saved to a file.
True
3
An Identity function usually tests its argument for the presence or absence of some property.
False
4
In scripts that include the definitions of several cooperating functions, it is often useful to define a special function named init that serves as the entry point for the script.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
Anytime you foresee using a list whose structure will not change, you can, and should, use a tuple instead.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
When replacing an element in a list, the subscript is used to reference the target of the assignment statement, which is not the list but an element's position within it.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
A list is a sequence of data values called indexes.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
To prevent aliasing, a new object can be created and the contents of the original can be copied to it.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
The definition of the main function and the other function definitions can appear in no particular order in the script, as long as main is called at the very end of the script.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
A list is immutable.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
Each item in a list has a unique index that specifies its position.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
A Python dictionary is written as a sequence of key/value pairs separated by commas. These pairs are sometimes called indexes.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
The index of the last item in a list is the length of the list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
The == operator returns True if the variables are aliases for the same object. Unfortunately, == returns False if the contents of two different objects are the same.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
The is operator has no way of distinguishing between object identity and structural equivalence.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The index of the first item in a list is 1.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
The main function usually expects no arguments and returns no value.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
Lists of integers can be built using the range function.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
The list method ascending mutates a list by arranging its elements in ascending order.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
The print function strips the quotation marks from a string, but it does not alter the look of a list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
When a Python script is running as a standalone program, what will the __name__ variable be set to?

A) The variable will hold the name of the script itself.
B) The variable will be set to "__main__".
C) The variable will be set to "standalone".
D) The variable will be set to "None".
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
What operator should you utilize if you wish to test for object identity between two objects?

A) ==
B) is
C) !=
D) @!
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
A lookup table is a type of dictionary.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
In order to create a docstring for a defined function, where should the docstring be?

A) The docstring should be just before the declaration of def.
B) The docstring should be placed at the end of the execution block for the function.
C) The docstring should be the next indented line after the def statement.
D) The docstring should be placed at the end of the function, before the return statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
What are the two arguments expected by the get method for a dictionary object? (Choose two.)

A) A possible key.
B) An index position.
C) A list of keys.
D) A default value.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
What statement regarding the use of lists is accurate?

A) The individual elements within a list are immutable, in that the values cannot be changed.
B) Two lists cannot be concatenated together, without the creation of a third list.
C) A list can be sliced into sublists.
D) When a list is evaluated, the elements are not evaluated.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
If pop is used with just one argument and this key is absent from the dictionary, Python raises an error.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
In a dictionary, a -> separates a key and its value.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
What statement accurately describes what a mutator is in the Python language?

A) A mutator is a method that converts immutable data into mutable data.
B) A mutator is a method used to encrypt text.
C) A mutator is a method that is devoted entirely to the modification of the internal state of an object.
D) A mutator is a method that changes the structure of a block of Python code.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
In a Python dictionary, an association is formed between what two components of the dictionary? (Choose two.)

A) lists
B) keys
C) values
D) indexes
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
What method should you utilize to add the elements of list2 onto the end of list1?

A) list1.extend(list2)
B) list1.append(list2)
C) list2.append(list1)
D) list2.extend(list1)
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
You add a new key/value pair to a dictionary by using the subscript operator [].
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
What statement accurately describes the use of a parameter in Python?

A) A parameter is the name used in the function definition for an argument that is passed to the function when it is called.
B) A parameter is the name used for a function that is then referenced by other parts of the program.
C) A parameter is the name used for data that is returned from the execution of a function.
D) A parameter is the name given to an acceptable range of values that are output from a program.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
The median of a list of values is the value that occurs most frequently.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
You are designing a script that may be imported as a module in other scripts. What variable can you use to check whether the script has been imported as a module, or is running as the main script?

A) __parent__
B) __name__
C) __operating_mode__
D) __status__
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
What list method should you use in order to remove and return the element at the end of the list named "books"?

A) books.get()
B) books.pop()
C) books.fetch()
D) books.pull()
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
What happens if you attempt to pop a key from a dictionary and the key does not exist, and you specified no default return?

A) The pop will return a None value.
B) The pop will return a value of 0.
C) The pop will return a value of False.
D) An error will be raised.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
What is the return value for a function that has no return statement defined?

A) The function will return a value of False.
B) The function will return a value of True, provided there are no errors.
C) The function will return a NULL value.
D) The function will return a special value of None.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
What statement accurately describes the difference between a list and a tuple?

A) A list is immutable, while a tuple is not.
B) A list is created with elements in parentheses, while a tuple is created with square brackets.
C) A tuple's contents cannot be changed.
D) A tuple can only hold integer and float data.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
A list is a sequence of data values known by either of what two terms? (Choose two.)

A) cards
B) instances
C) items
D) elements
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
When creating a list of items whose structure will not change, what should you ideally use to contain the values?

A) lists
B) tuples
C) dictionaries
D) strings
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
In computer science, what are two names that are used to describe data structures organized by association? (Choose two.)

A) matrices
B) tables
C) association lists
D) family trees
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
What happens if you use the following statement to sort a list of numbers called numbers? numbers = numbers.sort()

A) numbers is a value of None
B) The list is now ordered in ascending order.
C) The list is now ordered in descending order.
D) The numbers variable becomes a reference to a sorted list.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
When declaring a tuple, you enclose the tuple's elements in what two characters?

A) []
B) ()
C) {}
D) "Y"
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
What dictionary method can be utilized to access the entries in a dictionary variable with a name of parts?

A) parts.list()
B) parts.items()
C) parts.print()
D) parts.show()
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
What statement correctly defines what a median is?

A) A median is the minimum value that is smaller than all other values in a set.
B) A median is the maximum value that is greater than all other values in a set.
C) A median is the value that is less than half the numbers in a set and greater than the other half.
D) A median is the sum of all odd values in a set.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
You are creating a Python script that will make use of user input contact names and their associated phone numbers. What would be ideal for storing and accessing these associated values?

A) lists
B) tuples
C) dictionaries
D) strings
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
If you use the range method with a single parameter of 50, what will be the range of integers included in the returned list?

A) 0 through 50
B) 0 through 49
C) 1 through 50
D) 1 through 49
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Which of the following assigns a dictionary list of keys and values to the variable named persons?

A) persons = ["Sam":"CEO", "Julie":"President"]
B) persons = ("Sam":"CEO", "Julie":"President")
C) persons = {"Sam":"CEO", "Julie":"President"}
D) persons = {["Sam", "CEO"], ["Julie", "President"]}
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
What dictionary operation can you use to remove all the keys within the dictionary named contacts?

A) contacts.delete()
B) contacts.remove()
C) contacts.clear()
D) contacts.dump()
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.