Starting Out w/ Python: Ch. 9

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

2. True/False: Sets are immutable.

False

3. True/False: Sets are created using curly braces {}.

False

6. True/False: The union of two sets is a set that contains only the elements that appear in both sets.

False

8. True/False: The index of the first element in a set is 0.

False

9. True/False: The index of the first key-value pair in a dictionary is 0.

False

5. Each element in a(n) _______________ has two parts: a key and a value.

dictionary

10. To write an object to a file, you use the _______________ function of the _______________ module.

dump, pickle

13. Which of the following does not apply to sets? a. The stored elements can be of different data types. b. All the elements must be unique - no two elements can have the same value. c. The elements are unordered. d. The elements are pairs.

d. The elements are pairs.

1. True/False: You would typically use a for loop to iterate over the elements in a set.

True

10. True/False: The issubset method can be used to determine whether set1 is a subset of set2.

True

4. True/False: The set remove and discard methods behave differently only when a specified item is not found in the set.

True

5. True/False: A dictionary can include the same value several times, but cannot include the same key several times.

True

7. True/False: The difference of set1 and set2 is a set that contains only the elements that appear in set1 but do not appear in set2.

True

15. What is the process used to convert an object to a stream of bytes that can be saved in a file? a. Pickling b. Streaming c. Writing d. Dumping

a. Pickling

5. You created the following dictionary relationships = {'Jimmy':'brother'}. You then executed the following code, and received a KeyError exception. What is the reason for the exception? relationships['jimmy'] a. String comparisons are case sensitive so 'jimmy' does not equal 'Jimmy'. b. You used the wrong syntax for creating the dictionary. c. You should have used the code relationships['brother']. d. There is a bug in Python.

a. String comparisons are case sensitive so 'jimmy' does not equal 'Jimmy'.

8. Which statement would you use to delete an existing key-value pair from a dictionary? a. del b. remove c. delete d. unpair

a. del

4. To add a single item to a set, you can use the set method _______________.

add

1. In a dictionary, you use a(n) _____ to locate a specific value. a. datum b. element c. item d. key

d. key

11. Which method would you use to return the value associated with a specified key and remove that key-value pair from the dictionary? a. list b. items c. popitem d. pop

d. pop

10. Which method would you use to returns all the elements in the dictionary as a list of tuples? a. list b. items c. pop d. keys

b. items

2. What is the correct structure for creating a dictionary of month names to be accessed by month numbers? a. { 1 ; 'January', 2 ; 'February', 3 ; 'March' } b. { 1 : 'January', 2 : 'February', 3 : 'March' } c. [ 1 : 'January', 2 : 'February', 3 : 'March' ] d. { 1, 2, 3 : 'January', 'February', 'March' }

b. { 1 : 'January', 2 : 'February', 3 : 'March' }

7. What is the value of the variable phones after the execution of the following code? phones = {'John': '5555555', 'Julie' : '7777777'} phones['John'] = '1234567' a. {'John': '5555555', 'Julie' : '7777777'} b. {'John': '1234567', 'Julie' : '7777777'} c. {'John': '1234567' } d. invalid code

b. {'John': '1234567', 'Julie' : '7777777'}

4. What is the number of the first index in a list dictionary? a. 0 b. 1 c. Dictionary is not indexed by number. d. Size of the dictionary minus one.

c. Dictionary is not indexed by number.

12. What does the get method do if the specified key is not found in the dictionary? a. Throw an exception b. Nothing c. Return a default value d. You do not specify a key for the get method

c. Return a default value

6. In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the _____ operator. a. included b. of c. in d. not in

c. in

9. Which function would you use to get the number of elements in a dictionary? a. size b. length c. len d. invalid code

c. len

14. What method can be used to add a group of elements to a set? a. add b. addgroup c. update d. Elements must be added one at a time.

c. update

9. The _______________ method clears the contents of a dictionary.

clear

3. What would be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna'] a. false b. -1 c. 0 d. KeyError

d. KeyError

3. The built-in function _______________ returns the number of items in a set.

len

7. To determine whether a key is not included in a dictionary, or an element is not included in a set, you can use the _______________ operator.

not in

8. The _______________ method returns a value associated with a specified key and if found, removes that key-value pair from the dictionary.

pop

6. The elements in a dictionary are not stored in a specific order. Therefore a dictionary is not a(n) _______________.

sequence

1. A(n) _______________ is an object that holds multiple unique items of data in an unordered manner.

set

2. The _______________ of two sets is a set that contains all the elements of both sets.

union


Kaugnay na mga set ng pag-aaral

Ch.3 Exam - Health Insurance Policies: Medical Expense

View Set

Adaptive Learning Assignment: Chapter 15 - Databases

View Set

Introduction to Sociology (Chp. 1-10)

View Set

MBLEX - Massage Professional Practices

View Set

psych 161 chapter 9 and lecture 9

View Set

EAQ: hematology, anemia, neutropenia

View Set

bstrandable NCLEX Miscellaneous 2

View Set

BC: Access, Chapter 3, Review for Reassessment

View Set