M
mukesh tiwari
Hello all
I am trying to solve this problem[1] using regular expression. I wrote thiscode but I am getting time limit exceed. Could some one please tell me howto make this code run faster.
import re
if __name__ == "__main__":
n = int ( raw_input() )
c = 1
while c <= n :
email = filter ( lambda x : x != None , [ re.search ( '[^~!@#$%^&*()<>?,.]*[a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._]*@[a-zA-Z0-9]+.(com|edu|org|co.in)[^~!@#$%^&*()<>?,.a-zA-Z0-9]*' , x ) for x in raw_input().split(' ') ] )
t = len ( email )
print 'Case #' + str ( c ) + ': ' + str ( t )
for i in xrange ( t ):
print email.group()
c += 1
Also rather than breaking the string at space, I tried to use findall but Iam not getting correct result.
I am suppose to get [ (e-mail address removed) , (e-mail address removed)] ?
Regards
Mukesh Tiwari
[1] http://www.spoj.com/problems/MAIN12C/
I am trying to solve this problem[1] using regular expression. I wrote thiscode but I am getting time limit exceed. Could some one please tell me howto make this code run faster.
import re
if __name__ == "__main__":
n = int ( raw_input() )
c = 1
while c <= n :
email = filter ( lambda x : x != None , [ re.search ( '[^~!@#$%^&*()<>?,.]*[a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._]*@[a-zA-Z0-9]+.(com|edu|org|co.in)[^~!@#$%^&*()<>?,.a-zA-Z0-9]*' , x ) for x in raw_input().split(' ') ] )
t = len ( email )
print 'Case #' + str ( c ) + ': ' + str ( t )
for i in xrange ( t ):
print email.group()
c += 1
Also rather than breaking the string at space, I tried to use findall but Iam not getting correct result.
['com']re.findall ( '[^~!@#$%^&*()<>?,.]*[a-zA-Z0-9][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._][a-zA-Z0-9._]*@[a-zA-Z0-9]+.(com|edu|org|co.in)[^~!@#$%^&*()<>?,.a-zA-Z0-9]*[ ]+','(e-mail address removed) (e-mail address removed)')
I am suppose to get [ (e-mail address removed) , (e-mail address removed)] ?
Regards
Mukesh Tiwari
[1] http://www.spoj.com/problems/MAIN12C/