Let's say I have a file 'test.txt' and in it is huge amounts of text.
Now I am going to encode all of these characters into a custom binary/hex I wrote, but I can only use character I have pre-defined.
My question is, how can I define characters(in a LIST or a STRING), and have any other characters replaced with.. lets say a '?'
I have "abcdefg#~" in 'test.txt' file.
And I have the string:
char = '.,/?~abcdefg' #legal characters
>>> s = "test.,/?~abcdefgh" >>> legal = set('.,/?~abcdefg') >>> s = ''.join(char if char in legal else '?' for char in s) >>> s '?e??.,/?~abcdefg?' >>>