Skip to content

Instantly share code, notes, and snippets.

@kerenskybr
Last active September 18, 2020 12:30
Show Gist options
  • Save kerenskybr/4a432dd63cf221a4dc838d5d0f6466ed to your computer and use it in GitHub Desktop.
Save kerenskybr/4a432dd63cf221a4dc838d5d0f6466ed to your computer and use it in GitHub Desktop.
Creates dicts from list of lists
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