Just try this in the interpreter and see.
for key, value in sorted(months.items(), key=lambda x:x[1]):
print "%s %s" % (value, key)
--
http://mail.python.org/mailman/listinfo/python-list
for key, value in sorted(months.items(), key=lambda x:x[1]):
print("""'\t%s'\n""" % (value, key))
Explanation:
- - - - - -
dict.items is a method associated with dicts just like dict.keys or
dict.values, and returns a list of (key, value) pairs.
sorted and some other builtin functions have
Am 10.06.2013 15:37, schrieb Νικόλαος Κούρας:
Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt
έγραψε:
Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
Eckhardt έγραψε:
for key in sorted( months.ke
Since dict.keys() return a list of the keys in the dict and the keys are
associated with the dict's values why doesnt it work the other way around too?
I'm talking about this:
[code]
for key in sorted( months.keys() ):
print('''
%s
''' % (months[key], key)
Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt
έγραψε:
> Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
>
> > >Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
>
> > Eckhardt έγραψε:
>
> >
>
> > for key in sorted( months.keys() ):
>
> > pri
Τη Δευτέρα, 10 Ιουνίου 2013 4:14:33 μ.μ. UTC+3, ο χρήστης Ulrich Eckhardt
έγραψε:
> Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
>
> > >Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
>
> > Eckhardt έγραψε:
>
> >
>
> > for key in sorted( months.keys() ):
>
> > pri
Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
>Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
Eckhardt έγραψε:
for key in sorted( months.keys() ):
print('''
%s
''' % (months[key], key) )
this in fact works, it sorts the dict by its keys()
>Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
Eckhardt έγραψε:
for key in sorted( months.keys() ):
print('''
%s
''' % (months[key], key) )
this in fact works, it sorts the dict by its keys() was mistaken before
but the sorting aint correct