DEV Community

Discussion on: Daily Challenge #172 - Find All in an Array

Collapse
 
kerldev profile image
Kyle Jones

In Python:

def find_all(list, value):
    position = 0
    results = []
    for element in list:
        if element == value:
            results.append(position)
        position += 1
    return results

print(find_all([6, 9, 3, 4, 3, 82, 11], 2))
print(find_all([6, 9, 3, 4, 3, 82, 11], 3))
print(find_all([10, 16, 20, 6, 14, 11, 20, 2, 17, 16, 14], 16))
print(find_all([20, 20, 10, 13, 15, 2, 7, 2, 20, 3, 18, 2, 3, 2, 16, 10, 9, 9, 7, 5, 15, 5], 20))
print(find_all(["happy", "birthday", "to", "you", "happy", "birthday", "to", "me"], "happy"))