Neatest way to do a case insensitive "in"?
Steve Holden
steve at holdenweb.com
Thu Mar 19 15:34:02 EDT 2009
aiwarrior wrote:
> On Mar 13, 9:31 pm, Albert Hopkins <mar... at letterboxes.org> wrote:
>> On Fri, 2009-03-13 at 21:04 +0000, tinn... at isbd.co.uk wrote:
>>> What's the neatest way to do the following in case insensitive fashion:-
>>> if stringA in stringB:
>>> bla bla bla
>>> I know I can just do:-
>>> if stringA.lower() in stringB.lower():
>>> bla bla bla
>>> But I was wondering if there's a neater/easier way?
>> How is "if stringA.lower() in stringB.lower():" complex/messy?
>
> I do agree with you but what if your really insist and perhaps
> subclass the str and override the __contains__(x) method?
>
But then objects have to be explicitly created as subclasses of str.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Want to know? Come to PyCon - soon! http://us.pycon.org/
More information about the Python-list
mailing list