Find letter occurrences in a string
Input
find_indices('abracadabra', 'a')
Output
[0, 3, 5, 7, 10]
Returns each index where 'a' occurs in the string.
Full lesson preview
Find all positions of a target value in any iterable using enumerate for efficient index tracking.
Problem statement
Task
Examples
Input
find_indices('abracadabra', 'a')
Output
[0, 3, 5, 7, 10]
Returns each index where 'a' occurs in the string.
Input format
Output format
Constraints
Samples
Input
find_indices([1, 2, 3, 2, 1], 2)
Output
[1, 3]
Indices of value 2 in the list are 1 and 3.