0
0
Pythonprogramming~10 mins

Creating dictionary from two sequences in Python - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a dictionary by pairing keys and values from two lists.

Python
keys = ['a', 'b', 'c']
values = [1, 2, 3]
d = dict(zip(keys, [1]))
print(d)
Drag options to blanks, or click blank then click option'
Avalues
Bkeys
Crange(3)
Dlist
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using keys instead of values in zip.
Using range instead of the values list.
2fill in blank
medium

Complete the code to create a dictionary from two lists using a dictionary comprehension.

Python
keys = ['x', 'y', 'z']
values = [10, 20, 30]
d = {k: [1] for k, v in zip(keys, values)}
print(d)
Drag options to blanks, or click blank then click option'
Ak
Bvalues
Ckeys
Dv
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the key variable as the value.
Using the whole list instead of the variable.
3fill in blank
hard

Fix the error in the code to correctly create a dictionary from two lists.

Python
keys = ['name', 'age', 'city']
values = ['Alice', 30, 'NY']
d = dict([1](keys, values))
print(d)
Drag options to blanks, or click blank then click option'
Azip
Bmap
Cset
Dlist
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using map instead of zip.
Using list or set which do not pair elements.
4fill in blank
hard

Fill both blanks to create a dictionary from two lists where keys are uppercase.

Python
keys = ['a', 'b', 'c']
values = [1, 2, 3]
d = {k[1]: v for k, v in zip(keys, [2])}
print(d)
Drag options to blanks, or click blank then click option'
A.upper()
Bvalues
Ckeys
D.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using .lower() instead of .upper().
Zipping keys with keys instead of values.
5fill in blank
hard

Fill all three blanks to create a dictionary from two lists, including only pairs where value is greater than 10.

Python
keys = ['p', 'q', 'r', 's']
values = [5, 15, 25, 8]
d = {k[1]: v for k, v in zip([2], [3]) if v > 10}
print(d)
Drag options to blanks, or click blank then click option'
A.upper()
Bkeys
Cvalues
D.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using .lower() instead of .upper().
Swapping keys and values in zip.
Not filtering values greater than 10.