Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 19-06-2009
Member
 
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
Reply With Quote
  #2  
Old 19-06-2009
Member
 
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.
Reply With Quote
  #3  
Old 19-06-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "how to sort tuples of basis of numbers?"
Thread Thread Starter Forum Replies Last Post
What is the difference between binary tree sort and heap sort in data structure sRIPRIYA Software Development 3 04-01-2011 01:25 AM
How can you sort data in columns with Numbers for iPad? Aasha Portable Devices 3 01-10-2010 12:03 PM
program to sort numbers in java. Balamani Software Development 3 24-11-2009 10:18 PM
How to use Bubble sort in C# to sort parallel arraylists Ground 0 Software Development 3 03-08-2009 12:12 PM
how to delete or edit a tuples via vb.net Aberto Software Development 3 16-01-2009 12:49 PM


All times are GMT +5.5. The time now is 10:06 AM.