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'.

import re

pat = re.compile('good'+'bad') 

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']

pat.findall(a)

I want to search instances of both 'bad' and 'good' in a string. 

from the list 'a' above, I am expecting the result:

'good is an acceptable nature while bad is unwanted nature in a person'

 how can I define my pattern using re.compile. I appreciate your help. 

thank you. 

srini


      
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to