开发者

Comparing string in Python: String X is ASCII, and String Y is UTF

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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜