Case-insensitive string equality
Steve D'Aprano
steve+python at pearwood.info
Thu Aug 31 10:38:22 EDT 2017
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.
> 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 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]
We say, *not every* two line function needs to be a builtin, rather than **no**
two line function.
> Regular
> expressions solve the problem of case-insensitive searching a position
> of a substring.
And now you have two problems... *wink*
> 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.
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list