Skip to content

Instantly share code, notes, and snippets.

@dgouldin
Created March 31, 2014 19:51
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 dgouldin/9900741 to your computer and use it in GitHub Desktop.
Save dgouldin/9900741 to your computer and use it in GitHub Desktop.
def index_of_first(iterable, value):
match_func = value if callable(value) else (lambda x: x == value)
for index, item in enumerate(iterable):
if match_func(item):
return index
raise ValueError('Value not found')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment