The function:

def findOccurrences(s, ch):
    return [i for i, letter in enumerate(s) if letter == ch]


findOccurrences(yourString, '|')

will return a list of the indices of yourString in which the | occur.

Answer from Marco L. on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-all-occurrences-of-substring-in-string
Python - All occurrences of substring in string - GeeksforGeeks
July 12, 2025 - Use find() in a loop: The find() method is called repeatedly, starting from the last found position, to locate each occurrence of the substring "hello" in the string "hello world, hello universe".
Discussions

python - Find all occurrences of a character in a String - Stack Overflow
I'm really new to python and trying to build a Hangman Game for practice. I'm using Python 3.6.1 The User can enter a letter and I want to tell him if there is any occurrence of that letter in the... More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 1, 2017
python - How to find all occurrences of a substring? - Stack Overflow
Follow-up: How to find all occurrences of a substring in a string while ignore some characters in Python? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Find all the occurrences of a character in a given list of string in python language - Stack Overflow
this is example what i'm looking for. Example: Input: ['234','34','22','7','99'] 0:0 1:0 2:3 3:2 4:2 5:0 6:0 7:1 8:0 9:2 More on stackoverflow.com
๐ŸŒ stackoverflow.com
HELP - counting occurrences of all substrings within a list of strings.
This test: word.lower() in list_of_words[x].lower() is a in b and that's a Yes/No, True/False kind of test, it can't tell you how often the thing was found. For that you do need something like count() e.g. >>> 'rest and relaxation'.count('r') 2 >>> 'rest and relaxation'.count('rest') 1 And then you'll need to add that into your counter instead of adding 1 every time. More on reddit.com
๐ŸŒ r/learnpython
4
3
August 26, 2020
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ python-program-to-find-all-occurrence-of-a-character-in-a-string
Python Program to find All Occurrence of a Character in a String
January 22, 2025 - def all_Occurrence(ch, str1): for i in range(len(str1)): if(str1[i] == ch ): print(ch, " is Found at Position " , i + 1) string = input("Please enter your own String : ") char = input("Please enter your own Character : ") all_Occurrence(char, string)
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-find-indices-of-all-occurrences-of-character-in-string
Find all occurrences of a Substring in a String in Python | bobbyhadz
Use a list comprehension to iterate over a range object of the string's length. Check if each character starts with the given substring and return the result.
๐ŸŒ
PythonForBeginners.com
pythonforbeginners.com โ€บ home โ€บ find all occurrences of a substring in a string in python
Find All Occurrences of a Substring in a String in Python - PythonForBeginners.com
July 8, 2022 - With the help of a for loop, we can iterate through the characters in a string. To find all the occurrences of a substring in a string in python using a for loop, we will use the following steps.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ finding-all-occurrences-of-a-substring-in-a-python-string
Finding All Occurrences of a substring in a Python string
August 25, 2023 - #importing the "re" module import re #defining the function with two parameters as input string and substring def strfind(input_str, substr_list): # Regular expression is created and initialized as a shape shape = "(?=.*" + ")(?=.*".join(substr_list) + ").*" #using the findall() function to check ...
Find elsewhere
๐ŸŒ
pythontutorials
pythontutorials.net โ€บ blog โ€บ find-all-the-occurrences-of-a-character-in-a-string
How to Find All Occurrences of a Character in a String in Python: Fixing 'int' Object Not Iterable Error โ€” pythontutorials.net
It returns tuples of (index, value) for each item in the iterable (e.g., a string). How it works: Loop through the string with enumerate(), and collect indices where the character matches the target.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python find all occurrences in string
How to Find All Substring Occurrences in Python String | Delft Stack
February 2, 2024 - In Python, to use the str.find() method to find all occurrences of a substring in a string, you can create a loop that iterates through the string and uses str.find() to locate the substring.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 4664850 โ€บ how-to-find-all-occurrences-of-a-substring
python - How to find all occurrences of a substring? - Stack Overflow
Python has string.find() and string.rfind() to get the index of a substring in a string. I'm wondering whether there is something like string.find_all() which can return all found indexes (not only the first from the beginning or the first from ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
Finding All Occurrences of a Character in a String with Python: A Guide to index() and Beyond - YouTube
Discover how to find multiple occurrences of a character in a string using Python. Explore the limitations of the `index()` method and an alternative approac...
Published ย  May 25, 2025
Views ย  2
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ python-program-to-find-occurrence-to-each-character-in-given-string
Python program to find occurrence to each character in given string
Count of all characters in Tutorialspoint is : {'T': 1, 'u': 1, 't': 2, 'o': 2, 'r': 1, 'i': 2, 'a': 1, 'l': 1, 's': 1, 'p': 1, 'n': 1} This approach uses dictionary comprehension with set() to get unique characters and count their occurrences ? test_str = "Tutorialspoint" # using set() to calculate unique characters in the given string res = {i : test_str.count(i) for i in set(test_str)} print("Count of all characters in Tutorialspoint is :\n" + str(res))
๐ŸŒ
Quora
quora.com โ€บ How-do-you-count-the-occurrences-of-each-character-in-a-string-in-Python
How to count the occurrences of each character in a string in Python - Quora
Answer (1 of 3): While all the answers here work, I wouldnโ€™t really recommend them as far as Python is concerned because there are much better ways of doing this which are, indeed, faster than the solutions suggested. I have two alternatives. Sets and Dictionary Comprehensions Consider you have...
๐ŸŒ
PythonForBeginners.com
pythonforbeginners.com โ€บ home โ€บ count occurrences of each character in a string in python
Count Occurrences of Each Character in a String in Python - PythonForBeginners.com
August 3, 2022 - After execution, the count() method will return the number of occurrences of the current element of the set. We will print the value using the print statement. After execution of the for loop, the frequency of all the characters will be printed. You can observe this in the following example. ...
๐ŸŒ
Vultr
docs.vultr.com โ€บ python โ€บ examples โ€บ count-the-number-of-occurrence-of-a-character-in-string
Python Program to Count the Number of Occurrence of a Character in String | Vultr Docs
September 27, 2024 - Combine Pythonโ€™s sum() function and a list comprehension to count occurrences compactly. Check each character in the string and compare it to the target character. Sum up all matches to get the total count.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-find-occurrence-to-each-character-in-given-string
Python program to find occurrence to each character in given string - GeeksforGeeks
March 29, 2023 - Occurrence of all characters in GeeksforGeeks is : {'G': 2, 'e': 4, 'k': 2, 's': 2, 'f': 1, 'o': 1, 'r': 1} ... # Python3 code to program to find occurrence # to each character in given string from collections import Counter # initializing string in_str = "GeeksforGeeks" # using collections.Counter() to get # count of each element in string oup = Counter(in_str) # printing result print ("Occurrence of all characters in GeeksforGeeks is :\n "+ str(oup))
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-count-occurrences-of-a-character-in-string
Count Occurrences of a Character in String in Python - GeeksforGeeks
July 11, 2025 - The built-in count() method in the string class makes it easy to count how many times a character appears in a string. This is ideal for counting a single character quickly and easily.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python | list all occurrences of pattern in string
Python | List All Occurrences of Pattern in String - Be on the Right Side of Change
May 30, 2022 - s = 'Finxters learn Python with Finxter' pattern = 'Finxter' # Method 5: recursive, without regex def find_all(pattern, # string pattern string, # string to be searched start=0, # ignore everything before start acc=[]): # All occurrences of string pattern in string # Find next occurrence of pattern in string i = string.find(pattern, start) if i == -1: # Pattern not found in remaining string return acc return find_all(pattern, string, start = i+1, acc = acc + [(pattern, i)]) # Pass new list with found pattern l = find_all(pattern, s) print(l)