Starting Out with python - Chapter 9 Dictionaries and Sets

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

This operator can be used to find the intersection of two sets.

&

After the following statement executes, what elements will be stored in the myset set? myset = set('Saturn')

'S', 'a', 't', 'u', 'r', 'n'

After the following statement executes, what elements will be stored in the myset set? myset = set('a bb ccc dddd')

'a', 'b', ' ', 'c', 'd'

The following function returns the number of elements in a set:

. len()

What will the following code display? dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3} print(dct.get('Monday', 'Not found'))

1

What values will the following code display? (Don't worry about the order in which they will be displayed.) dct = {1:[0, 1], 2:[2, 3], 3:[4, 5]} for k in dct: print(k)

1, 2, 3

After the following statement executes, what elements will be stored in the myset set? myset = set([1, 1, 2, 3, 4, 4, 5])

1, 2, 3, 4, 5

What will the following code display? dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3} print(dct['Tuesday'])

2

After the following statement executes, what elements will be stored in the myset set? myset = set([2, 4, 4, 6, 6, 6, 6])

2, 4, 6

What will the following code display? stuff = {'aaa' : 111, 'bbb' : 222, 'ccc' : 333} print(stuff['bbb'])

222

A list can be a dictionary key.

False

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

False

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

False

The keys in a dictionary must be mutable objects.

False

You can store duplicate elements in a set.

False

What will the following code display? dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3} print(dct.get('Friday', 'Not found'))

Not found

A tuple can be a dictionary key.

True

Dictionaries are not sequences.

True

Sets store their elements in an unordered fashion.

True

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

True

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

True

After the following statement executes, what elements will be stored in the myset set? myset = set(10)

TypeError, as set() can only be called on an iterable object such as a list or string.

How do you delete an element from a dictionary?

Using the del statement, for example: del dct['Monday']

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

Using the len() function, for example: len(dct)

What will the following code display? dct = {1:[0, 1], 2:[2, 3], 3:[4, 5]} print(dct[3])

[4, 5]

This set method removes an element and raises an exception if the element is not found.

a. remove

You can add one element to a set with this method.

add

This set method removes an element, but does not raise an exception if the element is not found.

discard

The _________ dictionary method returns the value associated with a specified key. If the key is not found, it returns a default value.

get()

You can use the _________ operator to determine whether a key exists in a dictionary.

in

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

items()

The _________ function returns the number of elements in a dictionary:

len()

The _________ method returns the value associated with a specified key and removes that key-value pair from the dictionary.

pop()

The _________ method returns a randomly selected key-value pair from a dictionary.

popitem()

You use _________ to delete an element from a dictionary.

the del statement

You can add a group of elements to a set with this method.

update

You can use _________ to create an empty dictionary.

{}

This operator can be used to find the union of two sets.

|

This operator can be used to find the symmetric difference of two sets.

ˆ

This operator can be used to find the difference of two sets.


संबंधित स्टडी सेट्स

Algebra I Fundamentals A v.21 - LINEAR SYSTEMS ALTERNATE TEST

View Set

Unit Six: Meaning of Similarity - Theorems

View Set

HRM Chapter 10 Smartbook Questions, Chapter 8, HR MANAGE EXAM 3, MGMT 361 Exam 3 - Flores - Ball State, Chapter 10 - HR

View Set

Week 6 - Software Requirements Specification and Documentation

View Set

States of Consciousness chapter 9

View Set

Art Chapters 11-12 multiple choice

View Set

Module 8 (Chapter 16) Marcoeconomics

View Set