3
list1 = ['physics', 'chemistry', "dog", "cat","dog"];

I want it to say if I typed in an input dog it will tell me dog is the forth one and sixth one.

vaultah
  • 44,105
  • 12
  • 114
  • 143
jcdenton
  • 33
  • 3

1 Answers1

2

Use list comprehensions:

list1 = ['physics', 'chemistry', "dog", "cat","dog"]

string = input()
res = [i for i, el in enumerate(list1) if el == string]

print(res)

Output:

[2, 4]
Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67