Lisp mentality vs. Python mentality

Hrvoje Niksic hniksic at xemacs.org
Sat Apr 25 10:23:31 EDT 2009


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:

> "Ciprian Dorin, Craciun" <ciprian.craciun at gmail.com> writes:
>>     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...)
>
> In Lisp I think you'd use (equal (mapcar upcase a) (mapcar upcase
> b))

Or simply (equalp a b), since equalp comparisons happen to compare
strings case-insensitively.  But that's Common Lisp... overflowing
kitchen sink.

> or something like that.  In Python, a.upper() == b.upper().

I guess you meant map(a, str.upper) == map(b, str.upper)?  a and b are
lists of strings.



More information about the Python-list mailing list