jmquintana79
5/26/2016 - 6:36 AM

dictionary data

Manage python dictionaries

# get keys
mydict.keys()
# get values
mydict.values()
# get array of list of keys,values
mydict.items()

# browsing into dictionary
[v for k, v in mydict.items() if k in mykeys]

# sort dictionary by value (reverse)
from operator import itemgetter
dictionary_sorted = sorted(dictionary.items(), key=itemgetter(1))

# sort dictionary by index (reverse)
from operator import itemgetter
dictionary_sorted = sorted(dictionary.items(), key=itemgetter(0))