Re: [Demexp-dev] Sorting tag/question lists

2007-10-29 Par sujet David MENTRE
Hello Lyu,

2007/10/29, Lyu Abe [EMAIL PROTECTED]:
 I'm currently using this code to sort the question or tags lists...

You want to sort tag list by label name, right?

 tag_labels = []
 for k in range(n_maxtags):
 tag_labels += s.tag_info(cookie,k*100,100)

 tag_labels += s.tag_info(cookie,n_maxtags*100,n_maxtags_rem)

Using .map() and lambda you should be able to have a list tuples (id,
label) in tag_labels. From now, I assume you have something like:

  tag_labels=[(3, 'B'), (1, 'A')]


 z = []
 for k in range(max_tags):
 z += [(k,tag_labels[k]['a_tag_id'])]

 z.sort(lambda x,y:cmp(x[1],y[1]))

 o = []
 for k in range(max_tags):
 o += [ tag_labels[z[k][0]] ]

 tag_labels = o

Why don't you apply your .sort() directly on tag_labels? Something like:

   tag_labels.sort(lambda x,y:cmp(x[1],y[1]))

That gives:
   tag_labels
 [(1, 'A'), (3, 'B')]

I hope it helps,
Yours,
d.


___
Demexp-dev mailing list
Demexp-dev@nongnu.org
http://lists.nongnu.org/mailman/listinfo/demexp-dev


Re: [Demexp-dev] Sorting tag/question lists

2007-10-29 Par sujet Lyu Abe

Hi David,

thanks for your reply.


2007/10/29, Lyu Abe [EMAIL PROTECTED]:

I'm currently using this code to sort the question or tags lists...


You want to sort tag list by label name, right?


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?

Lyu


___
Demexp-dev mailing list
Demexp-dev@nongnu.org
http://lists.nongnu.org/mailman/listinfo/demexp-dev