Created
March 31, 2014 19:51
-
-
Save dgouldin/9900741 to your computer and use it in GitHub Desktop.
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
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