Sorting and list comprehension

Tran Tuan Anh anhtt at hotmail.com
Sun Oct 10 10:41:06 CEST 2004


Hi all,

I would like to do the followings, but I am quite new to Python hence
have not figured it out how...

salary = dictionary
salary["Bob"] = 11
salary["Marry"] = 4
salary["me"]= 45

How can I have a sort_value() function acts like this:
result = sortvalue(salary)
result = ["Marry","Bob","me"]

In sort, I would like to sort the key according to the values.

Regarding the list construction, how can I do this:

list = [item for item in list1 if for all item2 in list2 NOT
bad_condition(item, item2]

Anyone has any idea?
Thanks a lot!
Tuan-Anh



More information about the Python-list mailing list