why not "'in' in 'in'"?
Grant Griffin
not.this at seebelow.org
Thu Jun 13 11:32:13 EDT 2002
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:
>
>def is_in(search, search_for):
> """Return bool indicating whether search_for is in search."""
> return search.find(search_for) >= 0
>
>subject = "i like spam, i do."
>x = "spam"
>y = "ham"
>
>print is_in(subject, x)
>print is_in(subject, y)
>
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.
Ironically, that's already perfectly legal--so long as x has no more than one
character:
>>> subject = "i like spam, i do."
>>> x = "s"
>>> y = "h"
>>> if x in subject:
... print "x is in subject and x has no more than one character"
...
x is in subject and x has no more than one character
>>> if y in subject:
... print "same goes for y"
... else:
... print "can't say the same for y"
...
can't say the same for y
>>>
reluctant-to-discard-my-hard-won-near-mastery-of-"find"-ly y'rs,
=g2
_________________________________________________________________________
Grant R. Griffin g2 at dspguru.com
Publisher of dspGuru http://www.dspguru.com
Iowegian International Corporation http://www.iowegian.com
More information about the Python-list
mailing list