How can I define characters(in a LIST or a STRING), and have any other characters replaced with.. lets say a '?'
strinput = "abcdefg#~"
legal = '.,/?~abcdefg' #legal characters
while i not in legal:
#Turn i into '?'
>>> s = "test.,/?~abcdefgh" >>> legal = set('.,/?~abcdefg') >>> s = ''.join(char if char in legal else '?' for char in s) >>> s '?e??.,/?~abcdefg?' >>>