Question: PYTHON - IGNORE THE EMPTY BOXES... ____ is an example of an empty dictionary. [] {} () How do you search a dictionary named menu
PYTHON - IGNORE THE EMPTY BOXES...
____ is an example of an empty dictionary.
[]
{}
()
<>
How do you search a dictionary named menu for a key, but providing a default value in case it is not found?
"ood = menu.get("Fri", "seafood")
food = menu.get(["Fri"]), "seafod")
food = menu(["Fri"], "seafood")
food = get("seafood", "Fri")
What is printed by the following code snippet?
words = ["Today", "is", "Wednesday", "tomorrow", "is", "Thursday"] i = 0 while i < (len(words)) : word = words[i] if len(word) < 8 : words.pop(i) else : i = i + 1
print(words)
| ["Today", "is", "Wednesday", "tomorrow", "is", "Thursday"] | ||
| ["Wednesday"] | ||
| ["Wednesday", "tomorrow", "Thursday"] | ||
| ["Today", "is", "is"] |
"What is final version of the list names?
names = [] names.append("Amy") names.append("Boz") names.append("Peg") names[0] = "Cy" names.insert(0, "Sue") names.insert(4, "Savannah")
| ['Sue', 'Cy', 'Boz', 'Peg', 'Savannah'] | ||
| ['Sue', 'Cy', 'Amy', 'Boz', 'Peg', 'Savannah'] | ||
| ['Cy', 'Amy', 'Boz', 'Peg', 'Savannah'] | ||
| IndexError, list assignment index out of range |
What happens when this runs?
fruit = {"Apple": "Green", "Banana": "Yellow", "Plum": "Purple"}
for item in fruit.keys() : print(item + " ")
| It prints "Green Yellow Purple", in no particular order | ||
| It prints "Apple Banana Plum", in no particular order | ||
| It prints Apple Green Banana Yellow Plum Purple, in no particular order. | ||
| It prints "item item item" |
"What is printed after executing the following code?
somelist = ["a", "b", "c", "x", "y", "z"] for i in range(0, len(somelist), 2) print(somelist[i], end = " ")
| abcxyz | ||
| a b c x y z | ||
| acy | ||
| bcxz |
Which statement gets the length of the list values?
| numValues = length(values) | ||
| numValues = len(values) | ||
| numValues = size(values) | ||
| numValues = values.length |
What is the difference between a list and a dictionary?
| a list is a superset of a dictionary | ||
| a dictionary can access elements by position | ||
| a list stores individual elements but a dictionary stores key/value pairs |
What is output by the following code segment?
values = ["Q", "W", "E", "R", "T", "Y"] print(values[ 3 : ])
| ["W", "E"] | ||
| ["R", "T", "Y"] | ||
| ["Q", "u", "E", "R"] | ||
| ["E", "R", "T", "Y"] |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
