why not "'in' in 'in'"?
BPettersen at NAREX.com
Thu Jun 13 19:35:09 CEST 2002
> From: Grant Griffin [mailto:not.this at seebelow.org]
> In article <mailman.1023978378.11084.python-list at python.org>,
> "Mark says...
> >I haven't followed this thread. Someone else has probably already
> >suggested this, but in case they haven't, it's fairly easy to define
> >your own function that does what you want:
> That's not a bad suggestion, Mark, but if I did that I guess
> I would be forever wondering if I was testing whether the
> first one was in the second or the second one was in the
> first. Again, it doesn't read nearly as well as:
> if x in subject:
> which leaves no doubt.
Ok, how about:
>>> class mystr(str):
... def __contains__(self, s):
... return self.find(s) >= 0
>>> 'hello' in mystr('hello world')
>>> 'foo' in mystr('hello world')
More information about the Python-list