Python Week 8

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

A comprehension always produces a list.

False

A dictionary is bidirectional — values can be used to look up keys and vice versa.

False

A dictionary key must be a character string.

False

A for loop can be used to traverse a dictionary's keys, but not its values.

False

All values stored in a Python dictionary must be unique.

False

In the Counting Letters examples, the dictionary used to keep track of letter frequencies uses the count as the key.

False

Defining a class is an alternative to using a dictionary as a record.

True

What does the Hello World Translator program use to look up the language used given a phrase?

A list comprehension

The Hello World Translator program will produce an error if the language requested is not in the dictionary.

False

When printed, a set containing strings will list the elements in alphabetical order.

False

Which of the following is NOT an appropriate use case for a Python dictionary?

Representing an ordered sequence of values

Which of the following statements is true when using a dictionary for counting?

The key is the item counted, the value is the count

A dictionary is designed for efficient value retrieval. True

True

A generator expression has the same basic syntax as a list comprehension.

True

Checking to see if an element is in a set is an efficient operation in Python.

True

In the Counting Letters examples, only letters found in the analyzed text have entries in the dictionary.

True

The analysis of the complete I Have a Dream speech shows that four of the top five frequently used letters are vowels.

True

The codes used in Morse Code are influenced by the frequency of letter use in English communication. True

True

The content of the dictionary used in the Hello World Translator program is read from an input file. True

True

The dictionary used in the Hello World Translator program uses the language name as the key.

True

The if clause in a comprehension is optional.

True

The items method returns a list of key/value tuples for all entries in a dictionary.

True

The result of a comprehension could always be created using more verbose code.

True

Using the index operator to retrieve a value will result in a KeyError if the key is not in the dictionary.

True

When using a dictionary as a record, the name of the attribute is used as the key.

True

What value will the variable my_list hold after the following line of code is executed? my_list = [num for num in range(1, 20) if num % 3 == 0]

[3, 6, 9, 12, 15, 18]

What value will the variable stuff hold after the following code is executed? state = 'Mississippi' stuff = {ch.lower() for ch in state if ch != 'i'}

{'m', 's', 'p'}

What set is stored in set3 by the following code? set1 = {1, 2, 3, 4, 5} set2 = {3, 4, 5, 6, 7, 8, 9} set3 = set1 | set2

{1, 2, 3, 4, 5, 6, 7, 8, 9} because you combine the two lists but do not contain any duplicates; so although both have 3, 4, and 5, you would only list them once.

What set is stored in set3 by the following code? set1 = {1, 2, 3, 4, 5} set2 = {3, 4, 5, 6, 7, 8, 9} set3 = set1 - set2

{1, 2} because that is set one if you remove anything that both set1 and set2 have listed.

What set is stored in set3 by the following code? set1 = {1, 2, 3, 4, 5} set2 = {3, 4, 5, 6, 7, 8, 9} set3 = set1 & set2

{3, 4, 5} because the & symbol submits anything that both sets have listed.


Kaugnay na mga set ng pag-aaral

Client Confidentiality & Privilege

View Set

Targeted Med-Surg 2016 Cardiovascular

View Set

Human Resource Management Chpt. 10

View Set

Art History Benchmark (The Boat Party)

View Set

Clinical Anatomy 3.1 Skull(Bones, Joints, & Scalp)

View Set

Falconry Exam - Section 4 - Hunting & Training

View Set

CSE 230 Final Exam Review (Ch. 10)

View Set