Answer the question
In order to leave comments, you need to log in
What is the correct way to create a dictionary from two lists using itertools?
There are two lists of different lengths. The first contains the keys, and the second contains the values. Write a function that creates a dictionary from these keys and values. If the key didn't have enough value, the dictionary value should be None. Values that do not have enough keys should be ignored.
Answer the question
In order to leave comments, you need to log in
from itertools import zip_longest
{k: v for k, v in zip_longest(a, b) if k is not None}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question