1
2
3
4
5
6
7
8
9
10
11
12
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to Trinket.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
0,1,2,3,4,5,6,7,8,9,10,11
0
0
0
0
Code the first line to loop through the values in a dictionary. Make up the dictionary name and the name of the variable that stores each value. | for x in y.values(): | ^ *for [a-zA-Z_][a-zA-Z0-9_]* in [a-zA-Z_][a-zA-Z0-9_]*\.values\(\): *$ | |
Code the first line to loop through the keys of a dictionary. Make up the dictionary name and the name of the variable that stores keys. | for x in y.keys(): | ^ *for [a-zA-Z_][a-zA-Z0-9_]* in [a-zA-Z_][a-zA-Z0-9_]*\.keys\(\): *$ | |
Code the first line to loop through the keys of the customers dictionary. The name of the variable that holds the keys is k. | for k in customers.keys(): | for `k `in `customers`.`keys`(`)`: | |
Code the first line to loop through the elements in a list named numbers. The variable that holds the elements is num. | for num in numbers: | for num in numbers: | |
Loop through the keys of a dictionary. Display each key. Make everything up. | for x in y.keys(): print(x) | ^ *for ([a-zA-Z_][a-zA-Z0-9_]*) in [a-zA-Z_][a-zA-Z0-9_]*\.keys\(\):\n print\(\1\) *$ | |
In a single line, display the value paired with a key in a dictionary. The key is a string. Make up the name of the dictionary and the key. | print(capitals["Argentina"]) | ^ *print\([a-zA-Z_][a-zA-Z0-9_]*\[•.+•\]\) *$ | |
Loop through the keys in a dictionary and display the value for each key. Make everything up. | for a_key in products.keys(): print(a_key) | ^ *for ([a-zA-Z_][a-zA-Z0-9_]*) in ([a-zA-Z_][a-zA-Z0-9_]*)\.keys\(\):\n print\(\1\) *$ | |
Loop through a dictionary's keys. Append the value of each key to a list. Make everything up. | for a_key in cities.keys(): metro_list.append(a_key) | ^ *for ([a-zA-Z_][a-zA-Z0-9_]*) in ([a-zA-Z_][a-zA-Z0-9_]*)\.keys\(\):\n [a-zA-Z_][a-zA-Z0-9_]*\.append\(\1\) *$ | |
Loop through a dictionary's keys. If a key's value is greater than or equal to 99, display "ok" and break the loop. | for x in y.keys(): if x >= 99: print("ok") break | ^ *for ([a-zA-Z_][a-zA-Z0-9_]*) in ([a-zA-Z_][a-zA-Z0-9_]*)\.keys\(\):\n if \1\ >= 99:\n print\(•ok•\)\n break *$ | |
Loop through a dictionary's keys. Add each item—both its key and value—to a second dictionary. Make everything up. | for x in y.keys(): a[x] = y[x] | ^ *for ([a-zA-Z_][a-zA-Z0-9_]*) in ([a-zA-Z_][a-zA-Z0-9_]*)\.keys\(\):\n [a-zA-Z_][a-zA-Z0-9_]*\[\1\] = \2\[\1\] *$ | |
| 05b8b486bc | ||
| a8e5c3c503 |