Share Code Tips

Devyn Collier Johnson devyncjohnson at
Sat Jul 20 03:04:55 CEST 2013

On 07/19/2013 07:09 PM, Dave Angel wrote:
> On 07/19/2013 06:08 PM, Devyn Collier Johnson wrote:
>> On 07/19/2013 01:59 PM, Steven D'Aprano wrote:
>      <snip>
>> As for the case-insensitive if-statements, most code uses Latin letters.
>> Making a case-insensitive-international if-statement would be
>> interesting. I can tackle that later. For now, I only wanted to take
>> care of Latin letters. I hope to figure something out for all 
>> characters.
> Once Steven gave you the answer, what's to figure out?  You simply use 
> casefold() instead of lower().  The only constraint is it's 3.3 and 
> later, so you can't use it for anything earlier.
> """
> 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.
> New in version 3.3.
> """
Chris Angelico said that casefold is not perfect. In the future, I want 
to make the perfect international-case-insensitive if-statement. For 
now, my code only supports a limited range of characters. Even with 
casefold, I will have some issues as Chris Angelico mentioned. Also, "ß" 
is not really the same as "ss".


More information about the Python-list mailing list