Skip to content

Instantly share code, notes, and snippets.

@SZ-Edward
Created September 17, 2018 14:07
Show Gist options
  • Save SZ-Edward/003e53003e65850725f56e65c62a5b60 to your computer and use it in GitHub Desktop.
Save SZ-Edward/003e53003e65850725f56e65c62a5b60 to your computer and use it in GitHub Desktop.
def all_indices(value, qlist):
indices = []
idx = -1
while True:
try:
idx = qlist.index(value, idx + 1)
indices.append(idx)
except ValueError:
break
return indices
@SZ-Edward
Copy link
Author

SZ-Edward commented Sep 17, 2018

print(all_indices("foo", ["foo","bar","baz","foo"]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment