我试图在字符串中包含一个撇号,这样我就可以在文本文件中将其作为标点符号忽略

I am trying to inlcude an apostrophe in a string so I can ignore it as punctuation in a text file

所以我正在创建一个字符串,如下所示;

basic_punc = ' \n.,/?!:;()[]{}-~&\"\'—'

我正在尝试使用转义字符在我的字符串中包含撇号,以便在我的代码中:

if (not char.isalnum()) & (not char in basic_punc):
# Do the rest of my function here....

其中 char 是我正在查看的字符。但是,我的代码似乎无法识别撇号属于我的 basic_punc。我尝试用双引号将字符串括起来,删除转义字符,但我的函数继续将撇号视为不是我创建的字符串的一部分。我能做什么?如果相关的话,我正在使用 jupyter notebook。

更新:所以我一直在打印我一直在使用的词典,这是我的其余功能:

 if (not char.isalnum()) & (not char in basic_punc):
            # Look up if I have seen this character before!
            print(hidden)
            print(char)
            if not char in hidden: 
                hidden[char] = index
                index += 1 
                print("'" in hidden)

            # Find the second hidden character
            end = line.find(char, i+1)
            word = line[i+1:end]
            sentences[hidden.get(char)].append(word)
            line = line[end+1:]
            i = end

我的隐藏打印输出是: {'<': 0, '$': 1, '#': 2, ''': 3}。它说撇号不在我的字典里,但是这个字符是什么?

你的程序肯定还有其他的错误,原因:

>>basic_punc = ' \n.,/?!:;()[]{}-~&\"\'—'
>>'\'' in basic_punc
True
>>"'" in basic_punc
True