Deck 4: Introducing the Python Collections: Lists, Dictionaries, Tuples, and Statistics

Full screen (f)
exit full mode
Question
Case Study 1:
1. >>> m
2. >>> ??????
3. print(answer)
Output:
A
B
E
A
D
B
B
A
C
E
-Refer to the session in the accompanying Case Study 1. What program statements appear on line 2 to create the output listed in the case study?

A) if answer in myAnswers:
B) for answer in myAnswers:
C) print myAnswers:
D) for answer = myAnswers:
Use Space or
up arrow
down arrow
to flip the card.
Question
How is an empty list represented in Python?

A) []
B) ()
C) **
D) &It;>
Question
What will be the output based on the following lines of code?
>>> myList = [3, "cat", 6.5, 2]
>>> myList

A) 3
B) 4
C) [3, 'cat', 6.5, 2]
D) An error message because a list cannot contain different types of data
Question
What is the membership operator for lists?

A) []
B) +
C) *
D) in
Question
Case Study 2:
>>> changeList = [1, 2, "buckle my shoe", 3, 4,
"shut the door"]
2. >>> changeList
3. [1, 2, 'buckle my shoe', 3, 4, 'shut the door']
4. >>> changeList[2] = "the sky is blue"
5. >>> changeList
6. ??????
7. >>> name = "Monte"
8. >>> name[2] = "x"
9. ??????
-Refer to the session in the accompanying Case Study 2. What will be the output on line 6?

A) 'the sky is blue'
B) [1, 'the sky is blue', "buckle my shoe", 3, 4, 'shut the door']
C) [1, 2, 'the sky is blue', 3, 4, 'shut the door']
D) TypeError:object does not support item assignment
Question
Case Study 2:
>>> changeList = [1, 2, "buckle my shoe", 3, 4,
"shut the door"]
2. >>> changeList
3. [1, 2, 'buckle my shoe', 3, 4, 'shut the door']
4. >>> changeList[2] = "the sky is blue"
5. >>> changeList
6. ??????
7. >>> name = "Monte"
8. >>> name[2] = "x"
9. ??????
-Refer to the session in the accompanying Case Study 2. What will be the output on line 9?

A) "Monte"
B) "x"
C) "Moxte"
D) TypeError:object does not support item assignment
Question
Python provides the ____ function to create a list from a range or string.

A) list
B) append
C) insert
D) []
Question
The ____ list function removes and returns the last item in a list.

A) pop()
B) reverse()
C) remove(item)
D) count(item)
Question
One of the most often used measures of a collection of data is known as:

A) range.
B) central tendency.
C) dispersion.
D) mode.
Question
A Python ____ is a collection of associated pairs of items where each pair consists of a key and a value.

A) list
B) range
C) dictionary
D) string
Question
Case Study 3:
>>> ages = {'David':45, 'Brenda':46}
>>> ages
{'David': 45, 'Brenda': 46}
>>>
-Refer to the session in the accompanying Case Study 3. What will be the output after the following statement?
>>> ages['David']

A) {'David': 45}
B) 45
C) 'Brenda'
D) ages
Question
Case Study 3:
>>> ages = {'David':45, 'Brenda':46}
>>> ages
{'David': 45, 'Brenda': 46}
>>>
-Refer to the session in the accompanying Case Study 3. What will be the output after the following statement?
>>> ages['Kelsey'] = 19
>>> ages

A) 19
B) 'Kelsey'
C) {'Kelsey': 19}
D) {'David': 45, 'Brenda': 46, 'Kelsey': 19}
Question
What method is used to retrieve the value from a dictionary associated with a given key?

A) values
B) keys
C) get
D) del
Question
What statement is used to remove an entry from a dictionary based on a given key?

A) get
B) keys
C) del
D) index
Question
What represents the value(s) that occur most often in a set of data?

A) Average
B) Mode
C) Mean
D) Frequency distribution
Question
Lists in Python are sequences.
Question
Strings are mutable collections of data in which individual items within the string cannot be changed.
Question
The following Python statement creates a list of even numbers in ascending order:
list(range(10, 2, -2))
Question
Case Study 3:
>>> ages = {'David':45, 'Brenda':46}
>>> ages
{'David': 45, 'Brenda': 46}
>>>
-Refer to the session in the accompanying Case Study 3. The reference ages refers to a list.
Question
The values() method returns a dict_values object that behaves much like a list of the values in a dictionary.
Question
Match each definition with its term.
-Found by locating the item that occurs in the exact middle of a collection.

A) Median
B) Mode
C) Dispersion
D) Mean
Question
Match each definition with its term.
-The most frequently occurring value in a collection.

A) Median
B) Mode
C) Dispersion
D) Mean
Question
Match each definition with its term.
-Measure of how spread out data values in a collection are.

A) Median
B) Mode
C) Dispersion
D) Mean
Question
Match each definition with its term.
-Calculated by adding up the values in a collection and dividing by the number of items.

A) Median
B) Mode
C) Dispersion
D) Mean
Question
Define the concept of a list and describe some specific characteristics of lists in Python.
Question
Explain the meaning of the terms mutable and immutable.
Question
Describe the use of the split method for lists and provide an example of its use.
Question
How can Python be used to calculate dispersion?
Question
An interesting question arises when we consider what would happen if we did not have a built-in function to return the maximum value in the list. We could conceivably construct our own getMax function by iterating through the items in the list and keeping track of the largest value that we encounter. Provide an implementation of such a function.
Question
How would you use Python to find the mean value in a list?
Question
How would you find the mode of a list in Python?
Question
Describe two characteristics of Python dictionaries.
Question
How might you use Python to visualize a frequency distribution?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/33
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Introducing the Python Collections: Lists, Dictionaries, Tuples, and Statistics
1
Case Study 1:
1. >>> m
2. >>> ??????
3. print(answer)
Output:
A
B
E
A
D
B
B
A
C
E
-Refer to the session in the accompanying Case Study 1. What program statements appear on line 2 to create the output listed in the case study?

A) if answer in myAnswers:
B) for answer in myAnswers:
C) print myAnswers:
D) for answer = myAnswers:
B
2
How is an empty list represented in Python?

A) []
B) ()
C) **
D) &It;>
A
3
What will be the output based on the following lines of code?
>>> myList = [3, "cat", 6.5, 2]
>>> myList

A) 3
B) 4
C) [3, 'cat', 6.5, 2]
D) An error message because a list cannot contain different types of data
C
4
What is the membership operator for lists?

A) []
B) +
C) *
D) in
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
5
Case Study 2:
>>> changeList = [1, 2, "buckle my shoe", 3, 4,
"shut the door"]
2. >>> changeList
3. [1, 2, 'buckle my shoe', 3, 4, 'shut the door']
4. >>> changeList[2] = "the sky is blue"
5. >>> changeList
6. ??????
7. >>> name = "Monte"
8. >>> name[2] = "x"
9. ??????
-Refer to the session in the accompanying Case Study 2. What will be the output on line 6?

A) 'the sky is blue'
B) [1, 'the sky is blue', "buckle my shoe", 3, 4, 'shut the door']
C) [1, 2, 'the sky is blue', 3, 4, 'shut the door']
D) TypeError:object does not support item assignment
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
6
Case Study 2:
>>> changeList = [1, 2, "buckle my shoe", 3, 4,
"shut the door"]
2. >>> changeList
3. [1, 2, 'buckle my shoe', 3, 4, 'shut the door']
4. >>> changeList[2] = "the sky is blue"
5. >>> changeList
6. ??????
7. >>> name = "Monte"
8. >>> name[2] = "x"
9. ??????
-Refer to the session in the accompanying Case Study 2. What will be the output on line 9?

A) "Monte"
B) "x"
C) "Moxte"
D) TypeError:object does not support item assignment
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
7
Python provides the ____ function to create a list from a range or string.

A) list
B) append
C) insert
D) []
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
8
The ____ list function removes and returns the last item in a list.

A) pop()
B) reverse()
C) remove(item)
D) count(item)
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
9
One of the most often used measures of a collection of data is known as:

A) range.
B) central tendency.
C) dispersion.
D) mode.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
10
A Python ____ is a collection of associated pairs of items where each pair consists of a key and a value.

A) list
B) range
C) dictionary
D) string
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
11
Case Study 3:
>>> ages = {'David':45, 'Brenda':46}
>>> ages
{'David': 45, 'Brenda': 46}
>>>
-Refer to the session in the accompanying Case Study 3. What will be the output after the following statement?
>>> ages['David']

A) {'David': 45}
B) 45
C) 'Brenda'
D) ages
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
12
Case Study 3:
>>> ages = {'David':45, 'Brenda':46}
>>> ages
{'David': 45, 'Brenda': 46}
>>>
-Refer to the session in the accompanying Case Study 3. What will be the output after the following statement?
>>> ages['Kelsey'] = 19
>>> ages

A) 19
B) 'Kelsey'
C) {'Kelsey': 19}
D) {'David': 45, 'Brenda': 46, 'Kelsey': 19}
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
13
What method is used to retrieve the value from a dictionary associated with a given key?

A) values
B) keys
C) get
D) del
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
14
What statement is used to remove an entry from a dictionary based on a given key?

A) get
B) keys
C) del
D) index
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
15
What represents the value(s) that occur most often in a set of data?

A) Average
B) Mode
C) Mean
D) Frequency distribution
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
16
Lists in Python are sequences.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
17
Strings are mutable collections of data in which individual items within the string cannot be changed.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
18
The following Python statement creates a list of even numbers in ascending order:
list(range(10, 2, -2))
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
19
Case Study 3:
>>> ages = {'David':45, 'Brenda':46}
>>> ages
{'David': 45, 'Brenda': 46}
>>>
-Refer to the session in the accompanying Case Study 3. The reference ages refers to a list.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
20
The values() method returns a dict_values object that behaves much like a list of the values in a dictionary.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
21
Match each definition with its term.
-Found by locating the item that occurs in the exact middle of a collection.

A) Median
B) Mode
C) Dispersion
D) Mean
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
22
Match each definition with its term.
-The most frequently occurring value in a collection.

A) Median
B) Mode
C) Dispersion
D) Mean
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
23
Match each definition with its term.
-Measure of how spread out data values in a collection are.

A) Median
B) Mode
C) Dispersion
D) Mean
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
24
Match each definition with its term.
-Calculated by adding up the values in a collection and dividing by the number of items.

A) Median
B) Mode
C) Dispersion
D) Mean
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
25
Define the concept of a list and describe some specific characteristics of lists in Python.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
26
Explain the meaning of the terms mutable and immutable.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
27
Describe the use of the split method for lists and provide an example of its use.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
28
How can Python be used to calculate dispersion?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
29
An interesting question arises when we consider what would happen if we did not have a built-in function to return the maximum value in the list. We could conceivably construct our own getMax function by iterating through the items in the list and keeping track of the largest value that we encounter. Provide an implementation of such a function.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
30
How would you use Python to find the mean value in a list?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
31
How would you find the mode of a list in Python?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
32
Describe two characteristics of Python dictionaries.
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
33
How might you use Python to visualize a frequency distribution?
Unlock Deck
Unlock for access to all 33 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 33 flashcards in this deck.