How to append even and odd chars python
<p>I want to convert all the even letters using one function and all the odd numbers  using another function. So, each letter represents 0-25 correspsonding with a-z, so a,c,e,g,i,k,m,o,q,s,u,w,y are even characters.</p>

<p>However, only my even letters are converting correctly. </p>

<pre><code>def encrypt(plain):
    charCount = 0
    answer=[]
    for ch in plain:
        if charCount%2==0:
            answer.append(pycipher.Affine(7,6).encipher(ch))
        else:
            answer.append(pycipher.Affine(3,0).encipher(ch))
    return ''.join(answer)
</code></pre>

<p>Your basic approach is to re-encrypt a letter each time you see it. With only 26 possible characters to encrypt, it is probably worth pre-encrypting them, then just performing a lookup for each character in the plain text. While doing that, you don't need to compute the position of each character, because you know you are alternating between even and odd the entire time.</p>

<pre><code>import string

def encrypt(plain):
    # True == 1, False == 0
    fs = [pycipher.Affine(3,0).encipher,
          pycipher.Affine(7,6).encipher]
    is_even = True  # assuming "a" is even; otherwise, just set this to False
    d = dict()
    for ch in string.ascii_lowercase:
        f = fs[is_even]
        d[ch] = f(ch)
        is_even = not is_even

    return ''.join([d[ch] for ch in plain]) 
</code></pre>

<p>You can also use <code>itertools.cycle</code> to simplify the alternation for you.</p>

<pre><code>def encrypt(plain):
    # again, assuming a is even. If not, reverse this list
    fs = itertools.cycle([pycipher.Affine(3,0).encipher,
                          pycipher.Affine(7,6).encipher])
    d = dict((ch, f(ch)) for f, ch in zip(fs, string.ascii_lowercase))
    return ''.join([d[ch] for ch in plain])
</code></pre>

python