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.
More Related Contents:
- What does += mean in this context?
- Most efficient way to build single-element list from string with or without spaces? [closed]
- Python String concatenation with in double quotes [closed]
- How to convert a string in the desired manner?
- Why does comparing strings using either ‘==’ or ‘is’ sometimes produce a different result?
- How to extract numbers from a string in Python?
- How to search and replace text in a file?
- Convert hex string to int in Python
- How can I fill out a Python string with spaces?
- Stripping everything but alphanumeric chars from a string in Python
- How to display a float with two decimal places?
- Convert JSON string to dict using Python
- Print string to text file
- How can I do multiple substitutions using regex?
- What’s the difference between str.isdigit, isnumeric and isdecimal in python?
- How to match any string from a list of strings in regular expressions in python?
- Extract email sub-strings from large document
- Math operations from string [duplicate]
- How can I remove duplicate words in a string with Python?
- Does Python do slice-by-reference on strings?
- Time complexity of string concatenation in Python [duplicate]
- How do you extract a url from a string using python?
- Removing list of words from a string
- Safely evaluate simple string equation
- Strip spaces/tabs/newlines – python
- How to print like printf in Python3?
- Replacing specific words in a string (Python)
- How to change a string into uppercase
- Remove all newlines from inside a string
- Splitting a math expression string into tokens in Python