python -regular expression - list element

Chris cwitts at gmail.com
Wed Jun 25 07:33:12 EDT 2008


On Jun 25, 12:32 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
wrote:
> antar2 <desoth... at yahoo.com> writes:
> > for x in list1:
> >    re.compile(x)
> >    for y in list2:
> >            re.compile(y)
> >            if x in y:
> >                    z = re.sub(x, 'u', y)
> > but this does not work
>
> You need to frotz the hymangirator with spangule.
>
> That, or show us the actual result you're seeing and how it differs
> from what you expect to happen.
>
> --
>  \     "I must say that I find television very educational. The minute |
>   `\   somebody turns it on, I go to the library and read a book."  -- |
> _o__)                                                     Groucho Marx |
> Ben Finney

That made me laugh :D

Why not a list comprehension ?

::: list1 = ['a','o']
::: list2 = ['star',  'day', 'work', 'hello']
::: [l2.replace(l1,'u') for l2 in list2 for l1 in list1 if l1 in l2]
['stur', 'duy', 'wurk', 'hellu']



More information about the Python-list mailing list