On Mon, Sep 29, 2008 at 6:19 PM, Srinivas Iyyer
<[EMAIL PROTECTED]> wrote:
> Hi Tutors,
> I have a list with elements as strings. I want to search if any of these
> element strings has two words of my interest. How can I ask re.compile to
> look for both words.
>
> my words are 'good' and 'bad'.
If this really reflects your requirements, regular expressions are not
a good choice in the first place. Instead, I would use some of
python's built in string functionality, like this:
>>> a = ['Rama is a good boy','Raghu is a good boy','Sita is a good
>>> girl','Ravana is a bad boy','Duryodhan is a bad guy','good is an acceptable
>>> nature while bad is unwanted nature in a person']
>>> for item in a:
if 'good' in item and 'bad' in item:
print item
good is an acceptable nature while bad is unwanted nature in a person
>>>
--
Jerry
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor