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
  • 40,483
  • 12
  • 109
  • 137
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
  • 16,747
  • 3
  • 39
  • 66