Simon Forman wrote:
...
> I usually use this with assert statements when I need to check a
> sequence. Rather than:
>
> for something in something_else: assert expression
>
> I say
>
> assert False not in (expression for something in something_else)
>
> This way the whole assert statement will be r
On Thu, 06 Jul 2006 04:45:35 -0700, manstey wrote:
> Hi,
>
> I often use:
>
> a='yy'
> tup=('x','yy','asd')
> if a in tup:
><...>
>
> but I can't find an equivalent code for:
>
> a='xfsdfyysd asd x'
> tup=('x','yy','asd')
> if tup in a:
>< ...>
Of course you can't. Strings don't conta
manstey wrote:
> Hi,
>
> I often use:
>
> a='yy'
> tup=('x','yy','asd')
> if a in tup:
><...>
>
> but I can't find an equivalent code for:
>
> a='xfsdfyysd asd x'
> tup=('x','yy','asd')
> if tup in a:
>< ...>
>
> I can only do:
>
> if 'x' in a or 'yy' in a or 'asd' in a:
><...>
>
> but
"manstey" <[EMAIL PROTECTED]> wrote:
>I know I can do it this way. I wanted to know if there was another way.
if you don't want to write Python programs, why are you using Python ?
--
http://mail.python.org/mailman/listinfo/python-list
I know I can do it this way. I wanted to know if there was another way.
Fredrik Lundh wrote:
> "manstey" <[EMAIL PROTECTED]> wrote:
>
> > but I can't find an equivalent code for:
> >
> > a='xfsdfyysd asd x'
> > tup=('x','yy','asd')
> > if tup in a:
> > < ...>
> >
> > I can only do:
> >
> > if 'x
"manstey" <[EMAIL PROTECTED]> wrote:
> but I can't find an equivalent code for:
>
> a='xfsdfyysd asd x'
> tup=('x','yy','asd')
> if tup in a:
> < ...>
>
> I can only do:
>
> if 'x' in a or 'yy' in a or 'asd' in a:
> <...>
>
> but then I can't make the if clause dependent on changing value of t
You can get the matching elements with a list comprehension with
something like
py> a='xfsdfyysd asd x'
py> tup=('x','yy','asd')
py> [x for x in tup if x in a.split()]
['x', 'asd']
Hope this helps
manstey wrote:
> Hi,
>
> I often use:
>
> a='yy'
> tup=('x','yy','asd')
> if a in tup:
><...>
>
Hi,
I often use:
a='yy'
tup=('x','yy','asd')
if a in tup:
<...>
but I can't find an equivalent code for:
a='xfsdfyysd asd x'
tup=('x','yy','asd')
if tup in a:
< ...>
I can only do:
if 'x' in a or 'yy' in a or 'asd' in a:
<...>
but then I can't make the if clause dependent on changin