Case-insensitive string equality

Tim Chase python.list at tim.thechases.com
Thu Aug 31 11:34:37 EDT 2017


On 2017-08-31 23:30, Chris Angelico wrote:
> The method you proposed seems a little odd - it steps through the
> strings character by character and casefolds them separately. How is
> it superior to the two-line function? And it still doesn't solve any
> of your other cases.

It also breaks when casefold() returns multiple characters:

>>> s1 = 'ss'
>>> s2 = 'SS'
>>> s3 = 'ß'
>>> equal(s1,s2) # using Steve's equal() function
True
>>> equal(s1,s3)
False
>>> equal(s2,s3)
False
>>> s1.casefold() == s2.casefold()
True
>>> s1.casefold() == s3.casefold()
True
>>> s2.casefold() == s3.casefold()
True


-tkc






More information about the Python-list mailing list