Skip to content

Instantly share code, notes, and snippets.

@MHMDhub
MHMDhub / dictMerge.py
Created August 14, 2016 19:50
Merge two Python dictionaries
x = {'a':1, 'b': 2}
y = {'c':10, 'd': 11}
z = dict(x.items() + y.items())
z
{'a': 1, 'b':2, 'c': 10, 'd': 11}
@MHMDhub
MHMDhub / two-equal-lists-merge.py
Created August 14, 2016 19:39
Merge two equal-length lists into a dictionary, mapping one-to-many
Lst1 = ['11', '13', '11', '12', '11', '13', '12', '12', '12', '13', '11']
Lst2 = ['1/41', '1/34', '1/37', '1/47', '1/41', '1/33', '1/46', '1/45', 'p4', 'p5', 'p6']
Dict1 = {'11': ['1/41', '1/37', '1/141', 'p6'],
'12': ['1/47', '1/33', '1/46', 'p4'],
'13': ['1/34', '1/33', 'p5']}
Dict1 = {}
for key, val in zip(Lst1, Lst2):