Created
October 21, 2016 03:35
-
-
Save tanaikech/cfc419e6052a4f83c5e09dfd144797a9 to your computer and use it in GitHub Desktop.
Pythonでリスト内要素を要素、重複数として重複数でソートして出力 ref: http://qiita.com/tanaike/items/5a94e9bb1154d1caefca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = ['a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'b'] | |
result = sorted({i: data.count(i) for i in set(data)}.items(), key=lambda x: x[1], reverse=True) | |
print(result) | |
>>> [('b', 4), ('c', 3), ('d', 2), ('a', 1)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment