Lisp mentality vs. Python mentality

Ciprian Dorin, Craciun ciprian.craciun at gmail.com
Sat Apr 25 04:44:14 EDT 2009


On Sat, Apr 25, 2009 at 11:30 AM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>>>>     Ok... Then what's pythonic? Please give a pythonic implementation...
>>> Use the builtin a==b, similar to (equal a b)
>>
>>     But how about extensibility?
> [...]
>
> I see that you allow for a different comparison function. I do wonder
> what the use case for this is - in what application do you have to
> compare two lists for equality, and the item's __eq__ is inappropriate?
> What would break if you fix the item's __eq__, instead of writing
> your own comparison algorithm?
>
> [...]

    A practical example: I have lists that contain strings, but I want
to compare them in an case-insensitive way... 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...)



More information about the Python-list mailing list