Re: searching for strings (in a tuple) in a string

2006-07-14 Thread Simon Forman
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 removed if

Re: searching for strings (in a tuple) in a string

2006-07-07 Thread Steven D'Aprano
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 contain tuples, since

Re: searching for strings (in a tuple) in a string

2006-07-06 Thread [EMAIL PROTECTED]
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: ... but I can't

Re: searching for strings (in a tuple) in a string

2006-07-06 Thread Fredrik Lundh
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 tup. Is there a way

Re: searching for strings (in a tuple) in a string

2006-07-06 Thread manstey
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' in a or 'yy' in a or

Re: searching for strings (in a tuple) in a string

2006-07-06 Thread Fredrik Lundh
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 ? /F -- http://mail.python.org/mailman/listinfo/python-list

Re: searching for strings (in a tuple) in a string

2006-07-06 Thread Simon Forman
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 then I can't make the if