how can I move a list index value forward 'x' amount of times using python?
<p>I'm trying to unscramble a code using pythonic methods. The way to crack the code is by selecting the letter two places ahead of itself.</p>

<p>For example if the code was</p>

<pre><code>abc
</code></pre>

<p>Then the solution would be</p>

<pre><code>cde
</code></pre>

<p>So I am trying to figure out how I add 2 to the index value of a letter (given it is in a list like the following)</p>

<pre><code>alphabet = ["a","b","c"...."z"]
</code></pre>

<p>I am trying to write code similar to this</p>

<pre><code>def scramble(sentence):
    alphabet = ["a","b","c"...]
    solution = []
    for i in sentence:
        newIndex = get index value of i, += 2
        newLetter = translate newIndex into the corresponding letter
        solution.append(newLetter)
    for i in solution:
        print(i, end="")
</code></pre>

<p>But I am not yet skilled enough in python to figure it out</p>

<p>One solution would be to use enumerate:</p>

<pre><code>for idx, char in enumerate(sentence):
    # Do what you need to do here, idx is the index of the char, 
    # char is the char itself
    letter = sentence[idx + 2] # would get you the char 2 places ahead in the list
</code></pre>

<p>This way you could index in by adding to idx. Make sure you check for the end of the list though.</p>

<p>You could also wrap around the list by using modulus on the length of the list, so if you added 2 to the index 25 in a 26 element list, you would get 27 % 26 = 1, so the second element of the list again. </p>

python