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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:13:52+00:00 2026-05-17T15:13:52+00:00

I was wondering how can I make python order my collection of tuples so

  • 0

I was wondering how can I make python order my collection of tuples so that first similar items would appear grouped and groups ordered by first item.

order group
3     1
4     2
2     2
1     1

After sort

order group
1     1
3     1
2     2
4     2

Python list

unordered = [(3, 1), (4, 2), (2, 2), (1, 1)]
  • 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-17T15:13:53+00:00Added an answer on May 17, 2026 at 3:13 pm

    I assume you meant unordered = [(3, 1), (4, 2), (2, 2), (1, 1)] because that part of your example as you typed it is incompatible with the other two, right?

    If so, then

    >>> import operator
    >>> sorted(unordered, key=operator.itemgetter(1,0))
    [(1, 1), (3, 1), (2, 2), (4, 2)]
    

    or similarly unordered.sort(key=operator.itemgetter(1,0)) if you wanted to sort in place (which given the variable name I’m pretty sure you don’t — it would be seriously weird to name a variable “unordered” if it’s meant to be ordered!-).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wondering how you can implement a program similar to tail -f in C/C++,
I'm wondering if people can suggest the best tutorial that will walk me through
I'm wondering if anyone can recommend a good C++ tree implementation, hopefully one that
I was wondering how I can make a script load powerpoint file, advance slides
I was just wondering how do you make python fail in a user defined
From what I can make out, the two main HTML parsing libraries in Python
Is there an existing python module that can be used to detect which distro
I'm building my first python app on app-engine and wondering if I should use
I was wondering how to make a python script portable to both linux and
I am just wondering if I can make several button templates in WPF then

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.