Sorting a set works, sorting a dictionary fails ?
Fábio Santos
fabiosantosart at gmail.com
Mon Jun 10 06:13:09 EDT 2013
On 10 Jun 2013 10:53, "Νικόλαος Κούρας" <nikos.gr33k at gmail.com> wrote:
>
> After many tried this did the job:
>
> for key in sorted(months.items(),key=lambda num : num[1]):
> print('''
> <option value="%s"> %s </option>
> ''' % (key[1], key[0]) )
>
>
> but its really frustrating not being able to:
>
> for key in sorted( months.values() ):
> print('''
> <option value="%s"> %s </option>
> ''' % (months[key], key) )
>
> Which seemed to be an abivous way to do it.
> names set() was able to order like this why not the dictionary too?
Why not
for key, value in sorted(d.items()):
Tuples are totally sortable.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130610/e44f0594/attachment.html>
More information about the Python-list
mailing list