- List =[("Rail",2),("Airport",6),("Interstate",1),("jack",5),("Port",3),("intermodal",4),("MinPopulation",8),("Etc",7)]
i want to sort it like: - "Interstate",1
-
"Rail",2
-
"Port",3
-
"intermodal",4
-
"jack",5
-
"Airport",6
-
"Etc",7
-
"MinPopulation",8
I TRIED USING SORTED()BUT WAS NOT ABLE TO OBTAIN DESIRED RESULT: - sorted(List,key=operator.itemgetter(1))
cAN SOMEONE HELP ME WITH A BETTER SOLUTION?
1 1478 bvdet 2,851
Expert Mod 2GB
This is a solution for Python 2.3: - >>> List =[("Rail",2),("Airport",6),("Interstate",1),("jack",5),("Port",3),("intermodal",4),("MinPopulation",8),("Etc",7)]
-
>>> List.sort(lambda a,b: cmp(a[1], b[1]))
-
>>> List
-
[('Interstate', 1), ('Rail', 2), ('Port', 3), ('intermodal', 4), ('jack', 5), ('Airport', 6), ('Etc', 7), ('MinPopulation', 8)]
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jean-Paul Lauque |
last post by:
Hello,
I'm beginning in the ASP world...
I would like to sort (descending) list of files in directory.
Parameter is directory url.
How I can to do that with ASP not ASP.NET.
|
by: JC |
last post by:
Hello,
I'm running into a huge wall with linked lists.
If anyone outhere can help me, I'll appreciate it very much.
Here is my delima!
I need to create a simple list of numbers.
which I...
|
by: aquanutz |
last post by:
Ok, I have a list of strings (list<string> stringList) that I want to
sort alphabetcially, only "sort(stringList.begin(), stringList.end());
) does not work. Any insight would be helpful. Thanks!
|
by: Daniel |
last post by:
how do i call a stored proc that looks like this from ADO.NET? ALTER
PROCEDURE new_pzGetIDList ( @foo varbinary(8) ) i have it as a
System.Byte in C#
|
by: Lad |
last post by:
I have a list of emails and I would like to sorted that list by domains
E.g.
If the list is
Emails=
after sorting I would like to have
Emails=
What is the best/easiest way?
|
by: Lane Straatman |
last post by:
void s_sort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *))
{
size_t bytes;
unsigned char *array, *after, *i, *j, *k, *p1, *p2, *end, swap;
array = base;...
|
by: Tem |
last post by:
Thanks for all your responses. I see why c# is such a powerful language and
starting to like it more and more.
I also need help sorting this nested list. It is a little tricky. not sure
where to...
|
by: jr |
last post by:
I created a simple class, have used it to populate a list (of myclass)
- The class only contains a customer id and a date. I would like to
sort this list based on most recent date to the oldest....
|
by: Tem |
last post by:
What's a good way to sort a List<stringby the length of the strings from
longest to shortest. in c# 3
"aaaaaa"
"aaaaaaaaaa"
"aaa"
becomes
"aaaaaaaaaa"
"aaaaaa"
|
by: fastestindian |
last post by:
Hi,
I am working on the project where i show a list of Log Records.
my list is as follows.
Original list
Id Time Event Details
1 1 Error1 xyz
2 1 ...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |