What do you want to save?
Add Code snippet
New code examples
-
Python 2022-03-19 21:45:09
sort python dictionary by date
from datetime import datetime from collections import OrderedDict # For python 2.7 and above data = { "01-01-2015" : "some data", "05-05-2015" : "some data", "03-04-2015" : "some data&... Add solution -
Python 2022-02-27 22:15:07
OrederedDict
import collections #dictionnarry that remembers the order in which the items where given print 'Regular dictionary:' d = {} d['a'] = 'A' d['b'] = 'B' d['c'] = 'C' d['d'] = 'D' d['e'] = 'E' for k, v in d.items(): print k, v print '\nOrderedDict:' d =... Add solution -
Python 2021-11-19 12:00:29
python collections to dictionary
list = ["a","c","c","a","b","a","a","b","c"] cnt = Counter(list) od = OrderedDict(cnt.most_common()) for key, value in od.items(): print(key, value) Add solution -
Python 2021-11-09 21:56:07
defaultdict python
>>> # regular unsorted dictionary >>> d = {'banana': 3, 'apple': 4, 'pear': 1, 'orange': 2} >>> # dictionary sorted by key >>> OrderedDict(sorted(d.items(), key=lambda t: t[0])) OrderedDict([('apple', 4), ('banana', 3)... Add solution -
Python 2021-11-07 16:33:23
python get the last in dictionary
# import the right class from collections import OrderedDict # create and fill the dictionary d = OrderedDict() d['first'] = 1 d['second'] = 2 d['third'] = 3 # retrieve key/value pairs els = list(d.items()) # explicitly convert to a list, in case it's... Add solution
Best helpers
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5
+5