> list2 = ['star', day', 'work', 'hello']
>> Suppose that I want to substitute the vowels from list2 that are in
>> list1, into for example 'u'.
>> In my substitution, I should use the elements in list1 as a variable.
>> I thought about:
>> for x in list1:
> for y in li>t2:
> gt;if x in y:
> > z = re.sub(x, 'u', y)
> but this does not work
Others have given you several reasons why that doesn't work. Nothing I
have seen will work for words which contain both 'a' and 'o' however.
The most obvious way to do th>>>is probably to use a re:
>>> words = ['star', 'd>>>, 'work', 'hello', 'halo>>>
>>> vowels >>> 'a', 'o' ]
>>> import re
>>> vp =>>>.compile('|'.join(vowels))
>>> [vp.sub('u', w) for w in words]
['stur', 'd>>>, 'wurk', 'hellu', 'hulu']
However, the fastest way is probably to u>>>maketrans and translate:
>>> from strin>>>mport maketrans, translate
>>> trans = maketrans(''.j>>>(vowels), 'u'*len(vowels))
>>> [translate(w, trans) for w in words]
['stur', 'duy', 'wurk', 'hellu', 'hulu']