Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:53:20+00:00 2026-05-25T05:53:20+00:00

I have a dict, that looks like: channels = { ’24’: {‘type’: ‘plain’, ‘table_name’:

  • 0

I have a dict, that looks like:

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'}
}

i want to sort it by keys(’24’,’26’,’27’, etc…), it should be like:

channels = {
'20': {'type': 'plain', 'table_name': 'channel.gm.AvatarMoneyAssertChannel'}, 
'21': {'type': 'merged', 'table_name': 'channel.gm.AvatarKillMobComplexChannel'}, 
'22': {'type': 'plain', 'table_name': 'channel.gm.DistributionMarkChannel'}, 
'23': {'type': 'plain', 'table_name': 'channel.gm.MailChannel'}
'24': {'type': 'merged', 'table_name': 'channel.items.AuctionChannel'}, 
'26': {'type': 'plain', 'table_name': 'channel.gm.DeleteAvatarChannel'}, 
'27': {'type': 'plain', 'table_name': 'channel.gm.AvatarMoneyChannel'}, 
}

I have read articles, but i don’t understand how to sort by keys of main dict.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:53:20+00:00Added an answer on May 25, 2026 at 5:53 am

    a dict is a mapping, keys are not ordered. this is due to the way the dict() type is implemented: keys are hashed (using the hash() builtin function) and the order you observe derives from this hash.

    you will need an ordered dict for the dictionary to keep its ordering and to allow you to sort the keys. the collections.OrderedDict type is the builtin ordered dict for python 3.x.

    here is an example of sorting your data:

    import collections
    
    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rowset that looks like this: defaultdict(<type 'dict'>, { u'row1': {u'column1': 33,
I have a dict, that looks like this: { 'foo': { 'opt1': 1, 'opt2':
I have a dict that looks like this { keyword1:3 , keyword2:1 , keyword3:5
I have a very large defaultdict(dict) that looks something like this: data['w']['x']['y']['z']={'a':5,'b':10} I'm trying
I have a .plist file that looks like this: <plist version=1.0> <array> <dict> <key>name</key>
Hey, alright so I have a .plist that looks like; <plist version=1.0> <dict> <key>Item
I have a message definition file that looks like this struct1 { field=name type=string
I have a dict of configuration variables that looks something like this: self.config =
I have a plist that looks like this: <dict> <key>Aaron</key> <dict> <key>number</key> <string>1234</string> <key>country</key>
I have a list of dictionaries that looks like this: [{'id':1,'name':'Foo'},{'id':2,'name':'Bar'}] I'd like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.