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
Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
Eckhardt έγραψε:
for key in sorted( months.keys() ):
print('''
option value=%s %s /option
''' % (months[key], key) )
this in fact works, it sorts the dict by its keys() was mistaken before
but
Am 10.06.2013 12:57, schrieb Νικόλαος Κούρας:
Τη Δευτέρα, 10 Ιουνίου 2013 12:40:01 μ.μ. UTC+3, ο χρήστης Ulrich
Eckhardt έγραψε:
for key in sorted( months.keys() ):
print('''
option value=%s %s /option
''' % (months[key], key) )
this in fact works, it sorts
Τη Δευτέρα, 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() ):
print('''
Τη Δευτέρα, 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() ):
print('''
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('''
option value=%s %s /option
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(
for key, value in sorted(months.items(), key=lambda x:x[1]):
print('\toption value%s%s/option'\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