For loop with increasing variable
<p>I am writing a for loop to quickly obtain user data for a set. To keep the data useful, each has to have it's own variable it saves to. So far, I have:</p>

<pre><code>hey = ['11', '12', '13', '14']
x = 0
for i in hey:
    x += 1
    showtimesx = raw_input('NOG &gt;')
    print showtimesx

print ""   
print "Showtime at 11: " + showtimesx
print "Showtime at 12: " + showtimesx
print "Showtime at 13: " + showtimesx
print "Showtime at 14: " + showtimesx
</code></pre>

<p>The last prints are just to check that the showtimesx have increased in value. However, every time I run it, all of them just end up equaling the last inputted value. </p>

<p>I have attempted to move the x += 1 line, have the x = 0 line inside the loop and a series of other things, but none of them work.</p>

<p>How can I fix that?</p>

<h1>List Approach</h1>

<p>If you have to iterate through a and perform an operation with each value, try <a href="https://docs.python.org/2.3/whatsnew/section-enumerate.html" rel="nofollow"><code>enumerate()</code>, which will return both the value from your list and its position in the list</a>.<br>
This will also allow you to change the values in your list by index.</p>

<pre><code>mylist = ['11', '12', '13', '14']

for index, value in enumerate(mylist):
    if int(value) == 12:
        mylist[index] = "fifteen instead"

print mylist  # ['11', 'fifteen instead', '13', '14']
</code></pre>

<h1>Dictionary Approach</h1>

<p>In your case, <a href="http://www.tutorialspoint.com/python/python_dictionary.htm" rel="nofollow">consider using a dictionary</a>. This will allow you to more easily save them and query them back later by name ("key") instead of remembering some index like <code>mylist[1]</code> or having to search through it until you find a value.</p>

<pre><code>&gt;&gt;&gt; colors = {"pineapples": "sorry, no pineapples"}  # initial key: value pairs
&gt;&gt;&gt; colors["red"] = "#FF0000"  # add value
&gt;&gt;&gt; print colors["red"]  # retrieve a value by key
#FF0000
</code></pre>

<p>Here's an example as a complete function of your case:</p>

<pre><code>def showtimes(list_of_times, display=True):

    dict_of_times = {}  # empty dictionary to store your value pairs

    print "please enter values for the {} showtimes".format(len(list_of_times))
    for value in list_of_times:
        dict_of_times[value] = raw_input("NOG &gt; ")

    if display:  # Let the user decide to display or not
        print ""
        for time in sorted(dict_of_times.keys()):  # dictionaries are unsorted
            print "Showtimes at {}: {}".format(time, dict_of_times[time])

    return dict_of_times  # keep your new dictionary for later


hey = ['11', '12', '13', '14']
showtimes(hey)  # pass a list to your function
</code></pre>

python