Filling up a list, using input, and then using index to know position of value? python

Question:

I am trying to understand how to use index when i got a list from input.

count = 0
myListe = []

while True:
  
  
  empty_list = input("Input 5 values here: ")  
  myListe.append(empty_list)
  count += 1
  
  if count == 5:
    break  

Now i want to get an input that ask, what value in the list do you want to know the index number for.
So if i have ["New York", "Oslo", "Tokyo", 4, 3]

I want to be able to write for example Tokyo and then get back, "Its position 2"

I have been googling and checkin w3school but i an not sure how to do this

I got this code that i copied from somewhere but it is not working for me.

index = input("What value do you want to know the position for?")
index = int(index)
index = myList[index]
print(index)


 
Asked By: oljo

||

Answers:

If I’m understanding correctly, you are looking for something like this:

arr = ["New York", "Oslo", "Tokyo", 4, 3]
arr = [str(el) for el in arr]

x = input()

if x not in arr:
    print(f"{x} is not included")
else:
    print(arr.index(x))
Answered By: Dennis
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.