python - Find all the occurrences of a character in a string -
i trying find occurences of "|" in string.
def findsectionoffsets(text): startingpos = 0 endpos = len(text) position in text.find("|",startingpos, endpos): print position endpos = position
but error:
position in text.find("|",startingpos, endpos): typeerror: 'int' object not iterable
the function
def findoccurences(s, ch): return [i i, letter in enumerate(s) if letter == ch] findoccurrences(yourstring, "|")
will return list of indexes of yourstring in | occur