Skip to content

Instantly share code, notes, and snippets.

@seckcoder
Last active December 17, 2015 07:48
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 seckcoder/5575284 to your computer and use it in GitHub Desktop.
Save seckcoder/5575284 to your computer and use it in GitHub Desktop.
从一个字符串中找到从右往左数第3个下划线的index
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