Results 1 to 3 of 3

Thread: how to sort tuples of basis of numbers?

  1. #1
    Join Date
    Jan 2009
    Posts
    97

    how to sort tuples of basis of numbers?

    Hi,

    I have some problem with the display of my database.

    I have a huge data where the tuples have multiple elements like 3 or 4
    e.g.
    [('air', 456, 'orange'),('ball', 789, 'yellow'),('cat', 123, 'blue' ),('dog', 159, 'red')]
    So the problem is they are sorted by the alphabets for the first element which is a text(character),
    The problem is I want the tuples to be sorted on the basis of the second element.
    I want to soft the elements for the numbers (2nd element).

    Please help

  2. #2
    Join Date
    Jan 2009
    Posts
    34

    Re: how to sort tuples of basis of numbers?

    Try this:
    from opererator import itemgetter
    Code:
    MY_SORTED_TUPLE = tuple(sorted(MY_TUPLE, key=itemgetter(1)))
    or without itemgetter:
    Code:
    MY_SORTED_TUPLE = tuple(sorted(MY_TUPLE, key=lambda item: item[1]))
    I hope this helps.

  3. #3
    Join Date
    May 2008
    Posts
    29

    Re: how to sort tuples of basis of numbers?

    Hi,

    I think you need to go through this document here in the webpage at this site.
    http://homepage.mac.com/s_lott/books...s/ch32s03.html

    I hope this will help you.

Similar Threads

  1. Replies: 3
    Last Post: 04-01-2011, 01:25 AM
  2. How can you sort data in columns with Numbers for iPad?
    By Aasha in forum Portable Devices
    Replies: 3
    Last Post: 01-10-2010, 12:03 PM
  3. program to sort numbers in java.
    By Balamani in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 10:18 PM
  4. How to use Bubble sort in C# to sort parallel arraylists
    By Ground 0 in forum Software Development
    Replies: 3
    Last Post: 03-08-2009, 12:12 PM
  5. how to delete or edit a tuples via vb.net
    By Aberto in forum Software Development
    Replies: 3
    Last Post: 16-01-2009, 12:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,952,680.13698 seconds with 17 queries