Lists to Dictionary Conversion

Write a Python function that takes two lists as parameters (one for keys and the other for values) and converts these lists into a dictionary. Return the resulting dictionary.

Example 1:

Input: ['a', 'b', 'c'], [1, 2, 3] 
Output: {'a': 1, 'b': 2, 'c': 3}

Example 2:

Input: ['x', 'y', 'z'], [10, 20, 30] 
Output: {'x': 10, 'y': 20, 'z': 30}

Use Python’s built-in function ‘zip’ and ‘dict’ to convert two lists into a dictionary.

def lists_to_dict(keys, values):
    return dict(zip(keys, values))

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!