4
値でカウンターを並べ替える方法は?-python
逆リスト内包表記のリスト内包表記を行う以外に、カウンタを値でソートするためのPythonの方法はありますか?もしそうなら、それはこれより速いです: >>> from collections import Counter >>> x = Counter({'a':5, 'b':3, 'c':7}) >>> sorted(x) ['a', 'b', 'c'] >>> sorted(x.items()) [('a', 5), ('b', 3), ('c', 7)] >>> [(l,k) for k,l in sorted([(j,i) for i,j in x.items()])] [('b', 3), ('a', 5), ('c', 7)] >>> [(l,k) for k,l in sorted([(j,i) for i,j in …