Starting Out with Python, 3e Ch 9

Ace your homework & exams now with Quizwiz!

This operator can be used to find the difference of two sets. a. I b. & c. - d. ^

-

You can store duplicate elements in a set. T or F

False

The ____ method returns all of a dictionary's keys and their associated values as a sequence of tuples. a. keys_values( ) b. values( ) c. items ( ) d. get( )

items ( )

The ____ function returns the number of elements in a dictionary: a. size( ) b. len( ) c. elements( ) d. count( )

len( )

The following function returns the number of elements in a set: a. size( ) b. len( ) c. elements( ) d. count( )

len( )

What function do you call to pickle an object?

pickle.dump

This operator can be used to find the intersection of two sets. a. I b. & c. - d. ^

&

When you open a file for the purpose of retrieving a pickled object from it, what file access mode do you use?

'rb'

When you open a file for the purpose of saving a pickled object to it, what file access mode do you use?

'wb'

The ____ method returns the value associated with a specified key and removes that key-value pair from the dictionary . a. pop( ) b. random( ) c. popitem( ) d. rand_pop( )

pop( )

How do you delete an element from a dictionary?

By using the del statement

How do you determine the number of elements that are stored in a dictionary?

By using the len function

A list can be a dictionary key. T or F

False

The dictionary method popitem does not raise an exception if it is called on an empty dictionary. T or F

False

The following statement creates an empty set: myset = ( ) T or F

False

The keys in a dictionary must be mutable objects. T or F

False

What does the items method return?

It returns all a dictionary's keys and their associated values as a sequence of tuples.

What does the keys method return?

It returns all the 'keys' in a dictionary as a sequence of tuples.

What does the values method return?

It returns all the 'values' in the dictionary as a sequence of tuples.

A ______ is an object that stores a collection of data. Each element in a dictionary has two parts: a key and a value. You use a key to locate a specific value.

dictionary

This set method removes an element but does not raise an exception if the element is not found. a. remove b. discard c. delete d. erase

discard

The remove method raises an exception if the specified element is not found in the set. T or F

True

How do you create an empty set?

You call the built-in set function.

Are the elements of a set ordered or unordered?

Unordered

This operator can be used to find the union of two sets. a. I b. & c. - d. ^

I

What is the difference between the remove and discard methods?

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.

An element in a dictionary has two parts. What are they called?

Key and value

Does a set allow you to store duplicate elements?

No

The following statement creates an empty dictionary: mydct = { } T or F

True

______ a object is the process of converting the object to a stream of bytes that can be saved to a file for later retrieval.

Serializing

Which part of a dictionary element must be immutable?

The key

What module do you import if you want to pickle objects?

The pickle module

What is the difference between the dictionary methods pop and popitem?

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 object serialization?

The process of converting the object to a stream of bytes that can be saved to a file for later retrieval.

A tuple can be a dictionary key. T or F

True

Dictionaries are not sequences. T or F

True

Sets store their elements in an unordered fashion. T or F

True

How can you determine whether a key-value pair exists in a dictionary?

You can use the in operator to test for a specific key.

How can you determine whether a specific element exists in a set?

You can use the in operator to test for the element.

How do you determine the number of elements in a set?

You pass the set as an argument to the len function.

This operator can be used to find the symmetric difference of two sets. a. I b. & c. - d. ^

^

You can add one element to a set with this method. a. append b. add c. update d. merge

add

The ____ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value. a. pop( ) b. key( ) c. value( ) d. get( )

get( )

You can use the ____ operator to determine whether a key exists in a dictionary. a. & b. in c. ^ d. ?

in

What function do you call to retrieve and unpickle an object?

pickle.load

In Python, object serialization is called ______

pickling

The ____ method returns a randomly selected key-value pair from a dictionary. a. pop( ) b. random( ) c. popitem( ) d. rand pop( )

popitem( )

This set method removes an element and raises an exception if the element is not found. a. remove b. discard c. delete d. erase

remove

A ______ contains a collection of unique values and works like a mathematical set.

set

You use ____ to delete an element from a dictionary. a. the remove method b. the erase method c. the delete method d. the del statement

the del statement

You can add a group of elements to a set with this method. a. append b. add c. update d. merge

update

You can use ____ to create an empty dictionary. a. { } b. ( ) c. [ ] d. empty( )

{ }


Related study sets

Antigens and antigen presenting cells

View Set

CompTIA Network + 1.2 (Network Topologies and types)

View Set

Organic Fruits and Vegetable Production

View Set

Targeted Medical-Surgical: Endocrine

View Set