altering a word encoder and decoder to give recognize spaces and punctuation
<p>The 2nd function encodes a word phase and the 3rd one decodes that same word function but it doesn't skip over the spaces and punctuation. </p>

<pre><code>def buildCipher(key):
    alpha="abcdefghijklmnopqrstuvwxyz"
    rest = ""
    for letter in alpha:
      if not(letter in key):
        rest = rest + letter
    print key+rest

def encode(string,keyletters):
    alpha="abcdefghijklmnopqrstuvwxyz"
    secret = ""
    for letter in string:
      index = alpha.find(letter)
      secret = secret+keyletters[index]   
    print secret

def decode(secret,keyletters):
    alpha="abcdefghijklmnopqrstuvwxyz"
    clear = ""
    for letter in secret:
      index = keyletters.find(letter)
      clear = clear+alpha[index]

encode("this is zest!!!" , "earthbcdfgijklmnopqsuvwxyz")
#gives me sdfqfqzhqs
#need it to give me sdfq fq zhqs!!!
decode("tdfq fq zhqs!!!" , "earthbcdfgijklmnopqsuvwxyz")
</code></pre>

<p>What happens if <code>letter</code> isn't alphabetic? Exactly, it doesn't get added since it can't find it's index in <code>alpha</code>. You need to have an <code>if/else</code> statement:</p>

<pre><code>def encode(string,keyletters):
  alpha="abcdefghijklmnopqrstuvwxyz"
  secret = ""
  for letter in string:
    if letter in alpha:
      index = alpha.find(letter)
      secret = secret+keyletters[index]
    else:
      secret = secret + letter
  print secret
</code></pre>

python