Lecture

Create Dictionary from Key/Value Pairs - Solution

Explore 3 ways to create a dictionary from key/value pairs.


Method 1
def solution(keys, values): result = {} for i in range(len(keys)): # Use index to retrieve each key and value. result[keys[i]] = values[i] # Add key and value to the dictionary. return result

By using the code above, you can merge the input key list and value list to create a dictionary.


Example Usage

Input/Output Example
keys = ['a', 'b', 'c'] values = [1, 2, 3] result = solution(keys, values) print(result) # Output: {'a': 1, 'b': 2, 'c': 3}

Lecture

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help