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

  • Home
  • SEARCH
  • 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 8295293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:32:14+00:00 2026-06-08T14:32:14+00:00

Possible Duplicate: pythonic way to sort a list of lists by the last item

  • 0

Possible Duplicate:
pythonic way to sort a list of lists by the last item of the inner list

I have a list of list of numbers that looks like this:

rows = [[100,1.17902838317,4.30281847041,4.30598958666,4.31258472331,10.9269044537,1.17902838317]
[110,1.3978813526,1.39847341928,1.39950407438,1.4016475818,5.17927032236,1.3978813526]
[120,2.95045527752,2.95170493026,2.95388029498,2.95840451497,7.49578397746,2.95045527752]
[30,3.14439495993,3.145726755,3.14714447001,3.15196469714,7.9862122826,3.14439495993]
[40,3.35171204965,3.62204712952,3.62308999951,3.62767337976,8.49979359433,3.62120669609]
[50,2.63010055396,2.66403524005,2.66637361988,2.67045748911,6.76620535091,2.63010055396]
[60,3.09088634745,3.09219547918,3.09447438343,3.09921394005,9.71470661115,3.09088634745]
[70,1.42116996887,1.42199838776,1.42411423836,2.27074446576,3.60990507963,2.26985641041]
[80,1.7602934006,1.76103896537,1.76233682613,1.76503605518,4.4721162759,1.7602934006]
[90,1.27784662871,1.2783878552,1.27933000894,1.28128945544,3.24643534107,1.27784662871]
]

I want to write a sort func that will return the original list sorted using the integer in the first column, so the sorted list would look like this:

30,3.14439495993,3.145726755,3.14714447001,3.15196469714,7.9862122826,3.14439495993
40,3.35171204965,3.62204712952,3.62308999951,3.62767337976,8.49979359433,3.62120669609
50,2.63010055396,2.66403524005,2.66637361988,2.67045748911,6.76620535091,2.63010055396
60,3.09088634745,3.09219547918,3.09447438343,3.09921394005,9.71470661115,3.09088634745
70,1.42116996887,1.42199838776,1.42411423836,2.27074446576,3.60990507963,2.26985641041
80,1.7602934006,1.76103896537,1.76233682613,1.76503605518,4.4721162759,1.7602934006
90,1.27784662871,1.2783878552,1.27933000894,1.28128945544,3.24643534107,1.27784662871
100,1.17902838317,4.30281847041,4.30598958666,4.31258472331,10.9269044537,1.17902838317
110,1.3978813526,1.39847341928,1.39950407438,1.4016475818,5.17927032236,1.3978813526
120,2.95045527752,2.95170493026,2.95388029498,2.95840451497,7.49578397746,2.95045527752

How can I write such a custom sort function?

Attempt so far:

def mysort_func(row):
    # get the integer of row[1]
    # do something with it (simply return it?)
    pass


new_list = sorted(rows, key=mysort_func)
  • 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-06-08T14:32:15+00:00Added an answer on June 8, 2026 at 2:32 pm
    sorted(rows, key=lambda x: x[0])
    

    or

    import operator
    sorted(rows, key=operator.itemgetter(0))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Pythonic way to find maximum value and its index in a list?
Possible Duplicate: Python program to find fibonacci series. More Pythonic way. Hey, i was
Possible Duplicate: Pythonic way to check if a file exists? How can Check if
Possible Duplicate: iterate through pairs of items in python list I have a list
Possible Duplicate: Pythonic way to check if a file exists? How to check if
Possible Duplicate: Get difference from 2 lists. Python I have two lists rt =
Possible Duplicate: How to iterate through two lists in parallel? I have 2 lists:
Possible Duplicate: Is it Pythonic to use list comprehensions for just side effects? proper
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: Objective C for Windows iPhone development on Windows Is there any way

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.