You can not do that as dict
objects have unique keys. You should just the use list of tuple:
>>> alist = ['key1','key2','key3','key3','key4','key4','key5']
>>> blist= [30001,30002,30003,30003,30004,30004,30005]
>>> zip(alist, blist)
[('key1', 30001), ('key2', 30002), ('key3', 30003), ('key3', 30003), ('key4', 30004), ('key4', 30004), ('key5', 30005)]
If you want to access all the values based on the key, you may use collections.defaultdict
as:
>>> from collections import defaultdict
>>> my_dict = defaultdict(list)
>>> for k, v in zip(alist, blist):
... my_dict[k].append(v)
...
>>> my_dict
defaultdict(<type 'list'>, {'key3': [30003, 30003], 'key2': [30002], 'key1': [30001], 'key5': [30005], 'key4': [30004, 30004]})
You can access defaultdict
similar to normal dict objects. For example:
>>> my_dict['key3']
[30003, 30003]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…