开发者

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

开发者 https://www.devze.com 2023-02-22 05:45 出处:网络
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?

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

精彩评论

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