How can I convert a dictionary into a list of tuples?

>>> d = { 'a': 1, 'b': 2, 'c': 3 }
>>> list(d.items())
[('a', 1), ('c', 3), ('b', 2)]

For Python 3.6 and later, the order of the list is what you would expect.

In Python 2, you don’t need list.

Leave a Comment