kartshan
0
Q:

sort dict of dicts by key

sortedDictionary = sorted(mydictionary.keys())
3
A={1:2, -1:4, 4:-20}
{k:A[k] for k in sorted(A)}

output:
{-1: 4, 1: 2, 4: -20}
0
dictionary_items = a_dictionary.items()
sorted_items = sorted(dictionary_items)
0
channels = {
'24': {'type': 'plain', 'table_name': 'channel.items.AuctionChannel'}, 
'26': {'type': 'plain', 'table_name': 'channel.gm.DeleteAvatarChannel'}, 
'27': {'type': 'plain', 'table_name': 'channel.gm.AvatarMoneyChannel'}, 
'20': {'type': 'plain', 'table_name': 'channel.gm.AvatarMoneyAssertChannel'}, 
'21': {'type': 'plain', 'table_name': 'channel.gm.AvatarKillMobComplexChannel'}, 
'22': {'type': 'plain', 'table_name': 'channel.gm.DistributionMarkChannel'}, 
'23': {'type': 'plain', 'table_name': 'channel.gm.MailChannel'}
}

channels = collection.OrderedDict(sorted(channels.items(), key=lambda item: item[0]))
for key,value in channels.items():
    print(key, ':', value)
0

New to Communities?

Join the community