[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Demexp-dev] Sorting tag/question lists
From: |
David MENTRE |
Subject: |
Re: [Demexp-dev] Sorting tag/question lists |
Date: |
Mon, 29 Oct 2007 10:10:41 +0100 |
Hello Lyu,
2007/10/29, Lyu Abe <address@hidden>:
> No, I just want to order the questions tags by their 'q_id' (to match
> the question list sorting). But the .sort(lambda...) does not seem to
> work, because the list is a list of dictionnaries (if I got it right):
>
> tag_labels=[{'var1':8,'var2':'hello'},{'var1':2,'var2':'avec du lait'}]
>
> Any straightforward solution to this?
Yes, just apply the lambda to the correct subpart of each dictionnary.
>>> tag_labels
[{'var1': 8, 'var2': 'hello'}, {'var1': 2, 'var2': 'avec du lait'}]
>>> tag_labels.sort(lambda x,y:cmp(x['var1'],['var1']))
>>> tag_labels
[{'var1': 2, 'var2': 'avec du lait'}, {'var1': 8, 'var2': 'hello'}]
Python is convenient, isn't it? ;-)
Yours,
d.