Snippets

Idoenk . Heri Purnomo test-ordered-dict

Created by Idoenk . Heri Purnomo last modified
from collections import Counter
from collections import OrderedDict
import json

cnt = Counter()
for worh in ['red', 'blue', 'red', 'green', 'blue', 'brok']:
 cnt[worh] += 1

print cnt

a = OrderedDict(sorted(cnt.items(), key=lambda t: t[0]))

print a
d = {"result": a}

print json.dumps(d)

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.