I am trying to take a dictionary with key value pairs in which the values are a list and turn them into a list of tuples.
I have a the following dictionary:
d={'a': [33, 21, 4, 32], 'b': [6, 100, 8, 14]}
Desired output:
[(33, 6), (21, 100), (4, 8), (32, 14)]
Below is the code I tried but it does not get me there.
d={'a': [33, 21, 4, 32], 'b': [6, 100, 8, 14]}
# Converting into list of tuple
list = [(key, value) for key, value in d.items()]
# Printing list of tuple
print(list)
The code outputs a list value of :
[('a', [33, 21, 4, 32]), ('b', [6, 100, 8, 14])]
What am I doing wrong?
question from:
https://stackoverflow.com/questions/65834724/python-converting-dictionary-with-key-value-pairs-that-contain-a-list-of-values 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…