Complete the code to create a dictionary by pairing keys and values from two lists.
keys = ['a', 'b', 'c'] values = [1, 2, 3] d = dict(zip(keys, [1])) print(d)
The zip function pairs elements from keys and values. To create the dictionary, we need to zip keys with values.
Complete the code to create a dictionary from two lists using a dictionary comprehension.
keys = ['x', 'y', 'z'] values = [10, 20, 30] d = {k: [1] for k, v in zip(keys, values)} print(d)
In the comprehension, k is the key and v is the value from the zipped pairs. We want the dictionary to map keys to values, so the value is v.
Fix the error in the code to correctly create a dictionary from two lists.
keys = ['name', 'age', 'city'] values = ['Alice', 30, 'NY'] d = dict([1](keys, values)) print(d)
The dict function expects an iterable of key-value pairs. The zip function pairs elements from two lists, which is the correct input.
Fill both blanks to create a dictionary from two lists where keys are uppercase.
keys = ['a', 'b', 'c'] values = [1, 2, 3] d = {k[1]: v for k, v in zip(keys, [2])} print(d)
The keys are converted to uppercase using .upper(). The values come from the values list zipped with keys.
Fill all three blanks to create a dictionary from two lists, including only pairs where value is greater than 10.
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)
The keys are converted to uppercase with .upper(). The zipped lists are keys and values. The dictionary includes only pairs where the value is greater than 10.