splitting a dictionary in python into keys and values

dictionary, list, python

Solution

Not that hard, try `help(dict)` in a console for more info :)

keys = dictionary.keys()
values = dictionary.values()

For both keys and values:

items = dictionary.items()

Which can be used to split them as well:

keys, values = zip(*dictionary.items())

Note 0 The order of all of these is consistent within the same dictionary instance. The order of dictionaries in Python versions below 3.6 is arbitrary but constant for an instance. Since Python 3.6 the order depends on the insertion order.

Note 1 In Python 2 these all return a `list()` of results. For Python 3 you need to manually convert them if needed: `list(dictionary.keys())`

Problem

How can I take a dictionary and split it into two lists, one of keys, one of values. For example take: ``` {'name': 'Han Solo', 'firstname': 'Han', 'lastname': 'Solo', 'age': 37, 'score': 100, 'yrclass': 10} ``` and split it into: ``` ['name', 'firstname', 'lastname', 'age', 'score', 'yrclass'] # and ['Han Solo', 'Han', 'Solo', 36, 100, 10] ``` Any ideas guys?

Original source