Lisp mentality vs. Python mentality

"Martin v. Löwis" martin at v.loewis.de
Sat Apr 25 06:55:58 EDT 2009


>     A practical example: I have lists that contain strings, but I want
> to compare them in an case-insensitive way...

I'd claim that this is still theoretical: what are these strings, and
why do you have lists of them that you want to compare?

Why don't you try to lower-case the strings in the list as you
add them?

Also, are you sure a list is the best data structure for your problem?
Perhaps using a set would be better?

> Should I update the
> __eq__ method (for str class) and break almost everything? Can I write
> now a == b? Nop... I need the loop you've just mentioned in all the
> places where the comparison changes just in the operator, not in the
> algorithm... (I would say this is bad coding practice...)

If you want to compare the same lists in many places, this is indeed
bad coding practice. You should try to centralize whatever reasons
you have for comparing the lists into a few methods of the objects
holding the lists.

Regards,
Martin






More information about the Python-list mailing list