我有以下字符串列表:
exclude = ['eee', 'iii']
我有一个要测试的词:
word = 'Iîïe'
我希望以下测试成立:
if any(x in word for x in exclude):
#I want to be here !
为了成真,我的病情需要不区分大小写并且不重视......如何?
答案 0 :(得分:1)
您可以使用名为unidecode
的第三方软件包:
Unidecode提供的是一条中间道路:函数unidecode()接受Unicode数据并尝试用ASCII字符表示它(即0x00和0x7F之间的通用可显示字符),其中两个字符集之间的映射时所做的妥协是选择靠近美国键盘的人选。
示例:
from unidecode import unidecode
...
if any(x in unidecode(word).lower() for x in exclude):
...