finding variable in list
<p>I am trying to retrieve a word from a list; I am asking the user to input a word which is part of a list, I then want to find the position of the word in that list, for example,</p>

<pre><code>list = ["a", "b", "c", "d"]
list2 = [1,2,3,4]
</code></pre>

<p>With these lists, if the user inputs "a" then the computer works out that it is the first string in the list and picks out "1" from list2, or if they inputted "c", then it finds "3". However, due to the lists expanding and shrinking regularly, I can't use:</p>

<pre><code>if input == list[0]:
    variable = list2[0]
etc
</code></pre>

<p>I tried doing:</p>

<pre><code>y = 0
x = 1
while x == 1:
    if input == list[y]:
        variable = list2[y]
        x = 2
    else:
        y = y + 1
</code></pre>

<p>but that didn't work, so is there anyway that this can be done? or am I being a mong and missing the obvious...</p>

<pre><code>list1 = ["a", "b", "c", "d"]
list2 = [1,2,3,4]
x = input()
if x in list1 :
    print list2[list1.index(x)]
else :
    print "Error"
</code></pre>

python list python-3.x