I have 3 lists that I would like to put into a dictionary:
list1 = ['a', 'b', 'c']
list2 = [1, 2, 3]
list3 = [0.5, 0.3, 0.1]
Traditionally I could create a dictionary like this with just list1
, list2
my_dict = dict(zip(list1, list2))
# {'a': 1, 'b': 2, 'c': 3}
But what I would like to get is:
{'a': (1, 0.5), 'b': (2, 0.3), 'c': (3, 0.1)}
This did not work:
my_dict = dict(list1, zip(list2, list3))
You need to add one more zip, since dict
constructor accepts list of tuple
s, but not two list
s:
my_dict_3 = dict(zip(list1, zip(list2, list3)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With