[Tutor] project euler #4

Mats Wichmann mats at wichmann.us
Mon May 11 21:19:03 EDT 2020


On 5/11/20 5:39 PM, Alan Gauld via Tutor wrote:
> On 11/05/2020 19:08, Mats Wichmann wrote:
>>
>> def isPalindrome(n):
>>     n = str(n).casefold()  # eliminate any string case differences
> 
> I hadn't noticed casefold() before, but when I experiment it seems
> to be the same as lower(). What is the difference?
> The help() documentation doesn't clarify things much.
> 
> 


 str.casefold()

    Return a casefolded copy of the string. Casefolded strings may be
used for caseless matching.

    Casefolding is similar to lowercasing but more aggressive because it
is intended to remove all case distinctions in a string. For example,
the German lowercase letter 'ß' is equivalent to "ss". Since it is
already lowercase, lower() would do nothing to 'ß'; casefold() converts
it to "ss".

    The casefolding algorithm is described in section 3.13 of the
Unicode Standard.


More information about the Tutor mailing list