Skip to content

Instantly share code, notes, and snippets.

@Asuforce
Last active November 6, 2019 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Asuforce/8d49a66240288350f6e5ae31966a950d to your computer and use it in GitHub Desktop.
Save Asuforce/8d49a66240288350f6e5ae31966a950d to your computer and use it in GitHub Desktop.
内包記法の練習
>>> c = {str(i):i+random.randrange(10) for i in range(10)}
>>> c
{'0': 6, '1': 6, '2': 7, '3': 3, '4': 11, '5': 5, '6': 13, '7': 14, '8': 14, '9': 17}
>>> [l for l,r in sorted(c.items(), key=lambda x:x[1], reverse=True)][:16-len(c)]
['9', '7', '8', '6', '4', '2']

ref: https://qiita.com/ogrew/items/20a3d9a7edf1f7bd6a2c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment