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>Try:</p>

<pre><code>&gt;&gt;&gt; s = 'abc'
&gt;&gt;&gt; ''.join(chr(ord(c)+2) for c in s)
'cde'
</code></pre>

<p>The above is not limited to standard ASCII: it works up through the unicode character set.</p>

<h3>Limiting ourselves to 26 characters</h3>

<pre><code>&gt;&gt;&gt; s = 'abcyz'
&gt;&gt;&gt; ''.join(chr(ord('a')+(ord(c)-ord('a')+2) % 26) for c in s)
'cdeab'
</code></pre>

<h3>Modifying the original code</h3>

<p>If we want to modify the original only enough to get it working:</p>

<pre><code>from string import ascii_lowercase as alphabet

def scramble(sentence):
    solution = []
    for i in sentence:
        newIndex = (alphabet.index(i) + 2) % 26
        newLetter = alphabet[newIndex]
        solution.append(newLetter)
    for i in solution:
        print(i, end="")
</code></pre>

<p>Example:</p>

<pre><code>&gt;&gt;&gt; scramble('abcz')
cdeb
</code></pre>

python