how to iterate through a list and get values based on the value of the previous index in python?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python">How do you split a list into evenly sized chunks in Python?</a>  </p>
</blockquote>



<p>Basically, I have a list, and I am iterating through every odd numbered index in the list.  What I want to do, is based on the value of each odd numbered index, to then update a variable with the value in the even numbered index directly after said odd numbered index.</p>

<p>So if <code>lst[1]</code> contains the value <code>p</code>, then I want the value of <code>x</code> to be the value at <code>lst[2]: x = lst[2]</code>.  </p>

<p>If <code>lst[3]</code> contains the value <code>m</code> then I want y to be the value at <code>lst[4]: y = lst[4]</code></p>

<p>The length of the list is never set in stone, since it grabs it from a file.</p>

<p>I am currently iterating through the list using this code:</p>

<pre><code>for item in lst:
    if lst[range(1, len(lst), 2] == "p"
        x = ??
</code></pre>

<p>EDIT:  I suppose to be more specific, I have created a class, and now am creating a function that will take information from a file, and use it to fill in the methods in my class.  To do so I am reading in the file using <code>readlines</code> and then going through that list created by <code>readlines</code> and updating the methods in my class depending on what is in the file.  Every odd line in the file is an indicator of which method I need to update with the line that comes directly after.</p>

<p>So:</p>

<pre><code>if lst[1] == "p":
   s.methodOne(lst[2])
if lst[1] == "m":
    s.methodTwo(lst[2])
</code></pre>

<p>I'm just not sure how to grab what is in the even indexes after my odd ones.</p>

<p>My code is probably not very neat, but here is what I have so far:</p>

<pre><code>def processScores(fname):
    infile = open(fname, 'r')
    lineinfo = infile.readlines()
    infile.close()
    lstinfo = []
    for item in lineinfo:
        lst = item.split(",")
        s = Score()
        s.initialize(lst[0])
        if lst[range(1, len(lst -1), 2] == "o" or "O":
</code></pre>
