Created
October 22, 2014 22:04
-
-
Save ijp/c46f4fafea1e4fcc3865 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 rindex_func(func, l): | |
for (i,obj) in reversed(list(enumerate(l))): ## Boo! list() | |
if func(obj): | |
return i | |
return None | |
def only_as_suffix(obj, l): | |
try: | |
i = l.index(obj) | |
except ValueError: | |
return True | |
j = rindex_func(lambda x: x != obj, l) | |
if j: | |
return j < i | |
else: | |
return True | |
print only_as_suffix(0, [0,0]) # True | |
print only_as_suffix(0, [1,2,3,4]) # True | |
print only_as_suffix(0, [1,2,3,4,0]) # True | |
print only_as_suffix(0, [1,2,3,4,0,0,0]) # True | |
print only_as_suffix(0, [1,2,0,3,4,0]) # False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment