python sorting dictionary by length of values

>>> d = {"one": [(1,3),(1,4)], "two": [(1,2),(1,2),(1,3)], "three": [(1,1)]}
>>> for k in sorted(d, key=lambda k: len(d[k]), reverse=True):
        print k,


two one three

Here is a universal solution that works on Python 2 & Python 3:

>>> print(' '.join(sorted(d, key=lambda k: len(d[k]), reverse=True)))
two one three

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)