Python: Transform a Dictionary into a list of lists

to iterate over a dictionary's keys and values:

for key, value in D.iteritems():
    # do something with them

for key, value in my_dict.iteritems()

This will iterate through the dictionary, storing each key in key and each value in value. See the docs.


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]]