Case-insensitive string equality

Serhiy Storchaka storchaka at gmail.com
Thu Aug 31 11:16:29 EDT 2017


31.08.17 17:38, Steve D'Aprano пише:
> On Thu, 31 Aug 2017 11:45 pm, Serhiy Storchaka wrote:
> 
>> It is not clear what is your problem exactly.
> 
> That is fair. This is why I am discussing it here first, before taking it to
> Python-Ideas. At the moment my ideas on the matter are still half-formed.

What are you discussing? Without knowing what problem you are solving 
and what solution your are proposed it is hard to discuss it.

>> The easy one-line function
>> solves the problem of testing case-insensitive string equality.
> 
> True. Except that when a problem is as common as case-insensitive comparisons,
> there should be a standard solution, instead of having to re-invent the wheel
> over and over again. Even when the wheel is only two or three lines.

This *is* a standard solution. Don't invent the wheel, just use it properly.

> This is why we have dict.clear, for example, instead of:
> 
>      Just add this function to the top of every module and script
> 
>      def clear(d):
>          for key in list(d.keys()): del d[key]

No, there are other reasons for adding the clear() method in dict. 
Performance and atomicity (and the latter is more important).

> We say, *not every* two line function needs to be a builtin, rather than **no**
> two line function.

But there should be good reasons for this.

>> If you asked a solution that magically prevent people
>> from making simple programming mistakes, there is no such solution.
> 
> Very true. But when there is a common source of mistakes, we can help prevent
> that mistake.

How can you do this? I know only one way -- teaching and practicing.




More information about the Python-list mailing list