"str.contains(part)" or alternatives?

Steve Holden sholden at holdenweb.com
Thu Sep 12 11:49:19 EDT 2002


"Pete Shinners" <pete at shinners.org> wrote > Delaney, Timothy wrote:
> > In fact, this was the deciding factor in Guido changing his position on
'if
> > s1 in s2'. A string has sequence-like behaviour (e.g. it is iterable,
> > individual characters can be indexed), but also has its own behaviour
(e.g.
> > substring containment, all elements are single-character strings).
>
> does this mean we can also now do this? if so, nifty
>
>  >>> 1,2,3 in range(10)
> 1
>  >>> 3,2,1 in range(10)
> 0
>

No, you can't.

1,2,3 is in [1, (1, 2, 3), 2, 3]

but it won't be in [1, 2, 3, 4] - strings are a less general structure than
lists or tuples, and the "subsequence" implementation will apply to strings
*only*.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list