Lecture

Coding Quiz - Create a Dictionary from Key/Value Pairs

In this coding quiz, you are tasked with writing a function that receives two lists: one containing keys and another containing values, and combines them to create a dictionary.

Each key must be unique, and the length of the key list and the value list is always the same.

For example, given a key list ['a', 'b', 'c'] and a value list [1, 2, 3],

the dictionary created should be {'a': 1, 'b': 2, 'c': 3}.


Write Code
def solution(keys, values): # Write your code here return



Constraints

  • The lengths of the key list and the value list are always the same.

  • No key appears more than once in the key list.

  • Keys and values may be either strings or integers.




Example

  • Input: key list ['name', 'location', 'age'], value list ['John', 'New York', '28']

  • Output: {'name': 'John', 'location': 'New York', 'age': '28'}

Lecture

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help