|
| |||||||||
| Tags: sort, tuple |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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
| |||
| |||
| 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))) Code: MY_SORTED_TUPLE = tuple(sorted(MY_TUPLE, key=lambda item: item[1])) |
|
#3
| |||
| |||
| 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. |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 01: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 01:12 PM |
| how to delete or edit a tuples via vb.net | Aberto | Software Development | 3 | 16-01-2009 12:49 PM |