← Back to challenges

Sum of Found Indexes

PythonHardlanguage_fundamentalsarrays

Instructions

Create a function which takes in a list of numbers and a number to find. Return the sum of every index in the list which matches the chosen number.

Examples

sum_found_indexes([0, 3, 3, 0, 0, 3], 3) ➞ 8
# The number 3 was found at indexes 1, 2 and 5.
# 8 = 1 + 2 + 5

sum_found_indexes([1, 2, 3, 4, 5, 6], 3) ➞ 2

sum_found_indexes([100, 100, 100, 100, 100], 100) ➞ 10

sum_found_indexes([5, 10, 15, 20], 2) ➞ 0

Notes

0 can be the result if no number in the list matches or if the only matching element is at index 0.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Smaller String Number