I know this question was asked many times on here, but could not find an adequate answer.
I need to find the position of the words in a list, when I run my code it gives me None
Here is the code:
words = ['Banana', 'Banana', 'Apple', 'Apple', 'Pear', 'Peach', 'Grapefruit', 'St', 'Apple']
def get_position(words, type_word):
for idx, value in enumerate(words):
if value in words == type_word:
return idx
positions = get_position(words, 'Apple')
print(positions)
Preferred Output:
[2, 3, 8]