I want to get a list of all characters in a text file except for
[A-Z], [0-9], '|', '~'.
Appreciate your help.
I want to get a list of all characters in a text file except for
[A-Z], [0-9], '|', '~'.
Appreciate your help.
Step 1: Read in your file and convert it to a set of chars.
charset = set(open('file.txt').read())
Step 2: Join it back to a string with str.join
for the next step.
chars = ''.join(charset)
Step 3: Using regex, substitute all characters that you do not want with ''
, then display
import re
filtered_chars = re.sub('[A-Z0-9|~]', '', chars)
print(set(filtered_chars))
Other references (similar to your use case but not quite):