v Creating Lists From Dictionary Keys And Values - Python

Creating Lists From Dictionary Keys And Values

Create a dictionary

dict = {'county': ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma'], 
        'year': [2012, 2012, 2013, 2014, 2014], 
        'fireReports': [4, 24, 31, 2, 3]}

Create a list from the dictionary keys

# Create a list of keys
list(dict.keys())
['fireReports', 'year', 'county']

Create a list from the dictionary values

# Create a list of values
list(dict.values())
[[4, 24, 31, 2, 3],
 [2012, 2012, 2013, 2014, 2014],
 ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma']]