Skip to content

Instantly share code, notes, and snippets.

@jojonki
Last active November 14, 2017 22:07
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 jojonki/c430221ee97d56665307b12312b379fd to your computer and use it in GitHub Desktop.
Save jojonki/c430221ee97d56665307b12312b379fd to your computer and use it in GitHub Desktop.
return indices by value
# https://stackoverflow.com/questions/7851077/how-to-return-index-of-a-sorted-list
s = [2, 3, 1, 4, 5]
sorted(range(len(s)), key=lambda k: s[k])
# [2, 0, 1, 3, 4]
sorted(range(len(s)), key=lambda k: s[k], reverse=True)
# [4, 3, 1, 0, 2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment