I have a rather weird problem: How do I compare strings (using Python ) that where String X is ASCII and String Y is i开发者_JAVA百科n UTF or Unicode?
Currently, when I am comparing strings, I receive the following issue:
UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
filteredtext = [t for t in s if t.lower() not in stopwords]
How do I ensure that the strings are in the same format?
Best Regards.
Convert all string using the underlaying encoding and compare them:
print unicode(s1, 'ascii') == unicode(s1, 'utf-8')
精彩评论