Reputation: 173
I'm trying to set up a bot that deletes messages if they include a specific string from a list anywhere in their body.
This code works exactly how I think it should: (returns True)
s = 'test upvote test'
upvote_strings = ['upvote', 'up vote', 'doot']
print(any(x in s for x in upvote_strings))
But this does not: (returns False)
s = 'your upvotе bot thing works fine lmao'
upvote_strings = ['upvote', 'up vote', 'doot']
print(any(x in s for x in upvote_strings))
Upvotes: 4
Views: 66
Reputation: 362945
One of those e is not ASCII:
>>> import unicodedata
>>> unicodedata.name(s[10])
'CYRILLIC SMALL LETTER IE'
>>> unicodedata.name(upvote_strings[0][-1])
'LATIN SMALL LETTER E'
unidecode
can help:
>>> e1 = s[10]
>>> e2 = upvote_strings[0][-1]
>>> e1 == e2
False
>>> from unidecode import unidecode
>>> unidecode(e1) == "e" == unidecode(e2)
True
Upvotes: 6