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 6544741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:30:07+00:00 2026-05-25T11:30:07+00:00

I know there’s tonnes of questions on python sorting lists/dictionaries already, but I can’t

  • 0

I know there’s tonnes of questions on python sorting lists/dictionaries already, but I can’t seem to find one which helps in my case, and i’m looking for the most efficient solution as I’m going to be sorting a rather large dataset.

My data basically looks like this at the moment:

a = {'a': (1, 2, 3), 'b': (3, 2, 1)}

I’m basically creating a word list in which I store each word along with some stats about it (n, Sigma(x), Sigma(x^2) )

I want to sort it based on a particular stat. So far I’ve been trying something along the lines of:

b = a.items()
b.sort(key = itemgetter(1), reverse=True)

I’m not sure how to control which index it is sorted based on when its effectively a list of tuples of tuples? I guess I effectively need to nest two itemgetter operations but not really sure how to do this.

If there’s a better data structure I should be using instead please let me know. Should I perhaps create a small class/struct and then use a lambda function to access a member of the class?

Many Thanks

  • 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-25T11:30:07+00:00Added an answer on May 25, 2026 at 11:30 am

    Something like this?

    >>> a = {'a': (1, 2, 3), 'b': (3, 2, 1)}
    >>> b = a.items()
    >>> b
    [('a', (1, 2, 3)), ('b', (3, 2, 1))]
    >>> b.sort(key=lambda x:x[1][2])  # sorting by the third item in the tuple
    >>> b
    [('b', (3, 2, 1)), ('a', (1, 2, 3))]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there are similar questions already on SO but none of them seem
I know there has been similar questions before, but I can't find a solution
I know there are actually a number of questions similar to this one, but
I know there are several questions named like this, but they don't seem to
I know there are loads of questions on replacewith but none seem to have
I know there are already some solutions to this question but they don't seem
I know there are plenty of other questions addressing the same problem, but since
I know there are dozens of questions that ask about this error, but none
I know there are a lot of questions already posted with arabic language in
I know there are hundreds of questions about UTF-8 woes but I tried all

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.