Last active
September 18, 2020 12:30
-
-
Save kerenskybr/4a432dd63cf221a4dc838d5d0f6466ed to your computer and use it in GitHub Desktop.
Creates dicts from list of lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_items(a_list): | |
"""Merge the 4 lists of items | |
and combine as values to keys | |
""" | |
#Same amount of lists of lists to receive a key | |
keys = ['key1','key2','key3','key4'] | |
items = [list(i) for i in list(zip(*a_list))] | |
result = [] | |
for i in items: | |
result.append(dict(zip(keys, i))) | |
return result | |
"""I. e.: | |
a = [[1], [2], [3], [4]] | |
merge_items(a) | |
[{'key1': 1, 'key2': 2, 'key3': 3, 'key4': 4}] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment