Python 101 : From dictionaries to lists



Below are a couple of examples of how to turn a dictionary into a list.

Our first example used the items() method for form a list as we see below:



Our second example used the keys of our dictionary to form a list:


Our third example does the same, but this time using the dictionary's values:


Our fourth example does not convert a dictionary into a list using the list() method.
It populates a new list manually using the append() method:


Our last example uses list comprehension to populate a list using a dictionary:



Comments

Leave as a comment:

Archive