2

I have a rather weird problem: How do I compare strings (using Python ) that where String X is ASCII and String Y is in 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.

1
  • 1
    There's no such thing as "UTF". Commented Apr 3, 2011 at 16:56

1 Answer 1

6

Convert all string using the underlaying encoding and compare them:

print unicode(s1, 'ascii') == unicode(s1, 'utf-8')
Sign up to request clarification or add additional context in comments.

2 Comments

Unicode is not the "underlying encoding" of ASCII. It's more like a least common multiple.
"underlaying encoding" = encoding used for the related byte stream

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.