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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:55:13+00:00 2026-06-17T11:55:13+00:00

I have 3 lists: >>> a = [12, a] >>> b = [123, b]

  • 0

I have 3 lists:

>>> a = ["12", "a"]
>>> b = ["123", "b"]
>>> c = ["4", "c"]

I put them in a new list:

>>> d = [a,b,c]

When I sort them according to first item of each inner lists:

>>> sorted(d, key=itemgetter(0))
[['12', 'a'], ['123', 'b'], ['4', 'c']]

But I want:

[['4', 'c'], ['12', 'a'], ['123', 'b']]

Also, first item may have leading zero:

>>> a = ["012", "a"]
>>> b = ["0123", "b"]
>>> c = ["04", "c"]

Again, I want to see the sorted list this way:

[['04', 'c'], ['012', 'a'], ['0123', 'b']]

How can I do this?

  • 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-17T11:55:14+00:00Added an answer on June 17, 2026 at 11:55 am

    Just use int() in the key getter:

    In [5]: sorted(d, key=lambda x:int(x[0]))
    Out[5]: [['4', 'c'], ['12', 'a'], ['123', 'b']]
    

    In the second example:

    In [10]: sorted(d, key=lambda x:int(x[0]))
    Out[10]: [['04', 'c'], ['012', 'a'], ['0123', 'b']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have 2 lists of strings: List<string> firstList = new List<string>(010, 111, 123);
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have following: temp = aaaab123xyz@+ lists = [abc, 123.35, xyz, AND+] for list
I have lists of variable length where each item can be one of four
I have two lists see below.....result is coming back as empty List<Pay>olist = new
I have a (python) list of lists as below biglist=[ ['1','123-456','hello','there'],['2','987-456','program'],['1','123-456','list','of','lists'] ] I need
Say I have a list: [(12,34,1),(123,34,1),(21,23,1)] I want to remove the 1 from each
I have a lists: my_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456', 'def-111', 'qwe-111'] bad =
I have a list of string like: s = [(abc,bcd,cde),(123,3r4,32f)] Now I want to
I have lists where strings correspond with values. For example, in a company list

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.