Created
July 18, 2020 20:27
-
-
Save raeq/def9754284cab088c56980ca7187f08c to your computer and use it in GitHub Desktop.
Find character indexes in string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_char_locations(original: str = "", character: str = "") -> list: | |
return [index for index, char in enumerate(original) if char == character] | |
assert find_char_locations("The jolly green giant.", "e") == [2, 12, 13] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment