Last active
December 17, 2015 07:48
-
-
Save seckcoder/5575284 to your computer and use it in GitHub Desktop.
从一个字符串中找到从右往左数第3个下划线的index
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
import itertools | |
a = "abc_d_e_f" | |
print list(itertools.islice((i for i,c in enumerate(reversed(a)) if c == '_'), 3))[2] | |
def take(n, iterable): | |
return list(itertools.islice(iterable, n)) | |
print take(3, (i for i,c in enumerate(reversed(a)) if c == '_'))[2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment