Solution 1

def get_positions_of_char(another_string, char_being_searched_for):
    result = ""
    for pos, char in enumerate(another_string):
        if char == char_being_searched_for:
            result += str(pos) + ','
    return result

Get Positions of Char

Use a for loop with enumerate to complete the function get_positions_of_char so that it looks at another_string and searches for characters that match char_being_searched_for. If it's a match, add the position to a result string followed by a comma. Example:

get_positions_of_char("aabcda", "a") # Returns "0,1,5,"

Hint: You might have to put str() around to position to change it from an integer into a string so you can add it to your result string.

Test Cases

test get positions - Run Test

def test_get_positions():
    assert get_positions_of_char("XabcXdefXjahX", "X") == "0,4,8,12,"
def get_positions_of_char(another_string, char_being_searched_for): pass