Python Chapter 10 Terms and Concepts
dictionary: key, value
A _________ is an object that stores a collection of data whereby each elements has two parts: a ______ and a _______.
False
A list can be a dictionary key.
True
A tuple can be a dictionary key.
{1, 2}
After the following code executes, what elements will be members of set3? set1 = set(['a', 'b', 'c']) set2 = set(['b', 'c', 'd']) set3 = set1.symmetric_difference(set2)
{10, 20, 30, 100, 200, 300}
After the following code executes, what elements will be members of set3? set1 = set([1, 2, 3, 4]) set2 = set([3, 4, 5, 6]) set3 = set1.intersection(set2) 10.29 After the following code executes, what elements will be members of set3? set1 = set([1, 2, 3, 4]) set2 = set([3, 4, 5, 6]) set3 = set1.difference(set2)
{3, 4}
After the following code executes, what elements will be members of set3? set1 = set([1, 2, 3, 4]) set2 = set([3, 4, 5, 6]) set3 = set2.difference(set1)
You can use the in operator to test for the element.
After the following code executes, what elements will be members of set3? set1 = set([10, 20, 30]) set2 = set([100, 200, 300]) set3 = set1.union(set2) Look at the following code: set1 = set([1, 2, 3, 4]) set2 = set([2, 3]) Which of the sets is a subset of the other? Which of the sets is a superset of the other?
The set will contain these elements (in no particular order): 'w', '', 'x','y', and 'z'.
After the following statement executes, what elements will be stored in the myset set? myset = set('www xxx yyy zzz')
The set will contain one element: 25
After the following statement executes, what elements will be stored in the myset set? myset = set(25)
The set will contain these elements (in no particular order): 'www', 'xxx' 'yyy', and 'zzz'
After the following statement executes, what elements will be stored in the myset set? myset = set(['www', 'xxx', 'yyy', 'zzz'])
The set will contain these elements (in no particular order): 1, 2, 3, and 4
After the following statement executes, what elements will be stored in the myset set? myset = set([1, 2, 2, 3, 4, 4, 4])
The set will contain these elements (in no particular order): 10, 9, 8, 'a' , 'b' , and 'c' .
After the following statement executes, what elements will be stored in the myset set? myset = set([10, 9, 8]) myset.update('abc'
The set will contain these elements (in no particular order): 10, 9, 8, 1, 2, and 3
After the following statement executes, what elements will be stored in the myset set? myset = set([10, 9, 8]) myset.update([1, 2, 3])
The set will contain these elements (in no particular order): 'J' 'u' 'p' 'i' 't' 'e', and 'r'.
After the following statement executes, what elements will be stored in the myset set? myset = set('Jupiter')
Key and a value
An element in a dictionary has two pair. What are they called?
unordered
Are the elements of a set ordered or unordered?
symmetric_difference
Calling the __________ method will get the symmetric difference of two sets.
True
Dictionaries are not sequences.
key-value pairs
Dictionary elements are often referred to as __________.
no
Does a set allow you to store duplicate elements?
Serializing
Doing this to an object will convert it to a stream of bytes that can be saved to a file for later retrieval also know in Python as pickling.
You can use the in operator to test for a specific key.
How can you determine whether a key-value pair exists in a dictionary?
you call the built-in set function
How do you create an empty set?
You pass the set as an argument to the len function.
How do you determine the number of elements in a set?
issubset
If a one set has all the elements of another set this means that the first set is a superset and the following set is a subset. What method is used to determine if one set is a subset of another?
KeyError
If you use a non existent key there will be a __________ exception raised.
curly brackets
In order to create a dictionary, you must enclose the elements in ________.
in
In order to prevent KeyError exception, use the _________ operator to determine whether a key exists. Also used in sets.
{5, 6}
Look at the following code: set1 = set([1, 2, 3, 4]) set2 = set([2, 3]) Which of the sets is a subset of the other? Which of the sets is a superset of the other?
True
Sets store their elements in an unordered fashion.
The string 'start' is the key, and the integer 1472 is the value
Suppose 'start' : 1472 is an element in a dictionary. What is the key? What is the value?
It stores the key-value pair 'id' : 54321in the employee dictionary.
Suppose a dictionary named employee has been created. What does the following statement do? employee['id'] = 54321
it deletes the element that has the key 654
Suppose a dictionary named inventory exists. What does the following statement do? del inventory[654]
len
The _____ operator is a built-in function to get the number of elements in a dictionary. This operator can also be used to get a number from a set.
issuperset
The _______ method is used to determine if one set is the superset of another.
get()
The _________ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value.
len()
The _________ function returns the number of elements in a dictionary:
popitem()
The _________ method returns a randomly selected key-value pair from a dictionary.
items()
The _________ method returns all of a dictionary's keys and their associated values as a sequence of tuples.
pop()
The _________ method returns the value associated with a specified key, and removes that key-value pair from the dictionary.
False
The dictionary method popitem does not raise an exception if it is called on an empty dictionary.
len()
The following function returns the number of elements in a set:
True
The following statement creates an empty dictionary: mydct = {}
True
The following statement creates an empty set: myset = ()
False
The keys in a dictionary must be mutable objects.
True
The remove method raises an exception if the specified element is not found in the set.
not in
This is another operator beside 'in' to determine if a key exists in a dictionary. This can also be used in sets.
clear
This method clears the contents of a dictionary
get
This method finds the value associated with a specific key. However, it will not raise an exception if it is not found but will return a default value.
intersection
This method is used to get the intersection of two sets.
popitem
This method returns a randomly selected key-value pair as a tuple from the dictionary and removes that key-value from the dictionary.
items
This method returns all the keys in a dictionary and associated values as a sequence of tuples.
keys
This method returns all the keys in a dictionary as a sequence of tuples.
values
This method returns all the values in the dictionary as a sequence of tuples.
pop
This method returns the value associated with a specific key and removes that key-value pair from the dictionary.
-
This operator can be used to find the difference of two sets.
&
This operator can be used to find the intersection of two sets.
^
This operator can be used to find the symmetric difference of two sets.
|
This operator can be used to find the union of two sets.
remove
This set method removes an element and raises an exception if the element is not found.
discard
This set method removes an element but does not raise an exception if the element is not found.
False
True or False: The union of two sets is a set that contains one element of both sets.
True
True or False: You can create an empty dictionary and add elements to it when the program executes by using a set of curly brackets that are empty.
True
True or False: You cannot have duplicate keys in a dictionary
pickle
Use this module to serialize the object.
del
Use this statement as a way to delete an existing key-value pair from a dictionary.
for loop
Using a _________ allows you to iterate over all the keys in a dictionary
remove, discard
Using the ___________ and the__________ method will remove an item from a set.
it returns all a dictionary's keys and their associated values as a sequence of tuples.
What does the items method return?
It returns all the keys in a dictionary as a sequence of tuples
What does the keys method return?
It returns all the values in the dictionary as a sequence of tuples
What does the values method return?
'rb'
What function do you call to pickle an object?
The pickle module
What function do you call to retrieve and unpickle an object?
{'a', 'd'}
What is object serialization?
The pop method accepts a key as an argument, returns the value that is associated with that key, and removes that key-value pair from the dictionary. The popitem method returns a randomly selected key-value pair, as a tuple, and removes that key-value pair from the dictionary.
What is the difference between the dictionary methods pop and popitem?
If the specified element to delete is not in the set,the remove method raises a KeyError exception, but the discard method does not raise an exception.
What is the difference between the remove and discard methods?
'wb'
What module do you import if you want to pickle objects?
1 2 3
What will the following code display? stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'} for k in stuff: print(k)
3
What will the following code display? stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'} print(len(stuff))
ccc
What will the following code display? stuff = {1 : 'aaa', 2 : 'bbb', 3 : 'ccc'} print(stuff[3])
The process of converting the object to a stream of bytes that can be saved to a file for later retrieval.
When you open a file for the purpose of retrieving a pickled object from it, what file access mode do you use?
set2 is a subset of set1, and set1is a superset of set2.
When you open a file for the purpose of saving a pickled object to it, what file access mode do you use?
The key
Which part of a dictionary element must be immutable?
Lynn Figg
Who is the best teacher?
update
You can add a group of elements to a set with this method.
add
You can add one element to a set with this method.
False
You can store duplicate elements in a set.
{}
You can use _________ to create an empty dictionary
in
You can use the __________ operator to determine whether a key exists in a dictionary.
The delete statement
You use _________ to delete an element from a dictionary.
add
______ method is used to add elements to a set.
set
_________ contains a collection of unique values and works like a mathematical set.
mappings
___________ is another reference to key-value pairs.
difference
___________ method is used to get the difference of two sets.
update
____________ method is used to add a group of elements to a set all at one time.