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


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo