Q:

How can i get python to check if every term of a input is in list1, and if not print the term as is?

This is my code so far. I'm trying to "decode" the user's input by printing the character n1 spaces ahead but I'm looking for a way to print characters that aren't letters unaltered
n=input("Enter code")
n1=int(n[0])
newcode=n[1:]
list1=['a','b','c','d','e','f','g','h','i','j','k','l'
   ,'m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B',
   'C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R'
   ,'S','T','U','V','W','X','Y','Z']
list2=[]
for x in newcode:
    n=list1.index(x)
    n2=n-n1
    y=list1[n2]
    print(y)

> Sample input: 3wkh 
>sample output: 
>t 
>h 
>e 
>sample input: 3wkh fdu 
>sample output: 
>t 
>h 
>e 
Traceback (most recent call last):   
>File "D:\Computer Science\Comp Sci club problems\data1.py", line 10, in <module>
>     n=list1.index(x) ValueError: ' ' is not in list 
>This is the problem that i am having. Please help! 

A:

You can add a check to see whether the given element is in the list before the line:
n=list1.index(x)

like this:
if x in list1:
    n=list1.index(x)
    n2=n-n1
    y=list1[n2]
    print(y)
else:
    print(x)

but to finish the problem, I guess you want the transformed list to be stored in list2, right? In that case you could do this:
st = ''
for x in newcode:
    if x in list1:
        n=list1.index(x)
        n2=n-n1
        y=list1[n2]
        st += y
    else:
        st += x
print(st)

This is a quick and dirty way to put all your characters in a string called st, and then print out the string at the end.

