Logo

Programming-Idioms

History of Idiom 113 > diff from v19 to v20

Edit summary for version 20 by Oldboy:
New Python implementation by user [Oldboy]

Version 19

2016-10-18, 21:25:51

Version 20

2017-10-28, 12:30:49

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
for x, k in sorted((x, k) for k,x in mymap.items()):
    print(k, x)