Basically, I have a dictionary that I want to transform into a list of lists (with each component list consisting of the key and value from the dictionary).
The reason I am doing this is so that I can iterate through this new list with a for loop and do something with both the key and the value. If there is an easier way to do this, I am open to suggestions.
How about this solution ? No need to make your hand dirty by unnecessary looping through, cleaner and shorter !!!
d = { 'a': 1, 'b': 2, 'c': 3 }
list(map(list, d.items()))
[['a', 1], ['c', 3], ['b', 2]]
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