Friday, 15 May 2015

I want to implement OR operator in find() in python -



I want to implement OR operator in find() in python -

while compiling next code not getting syntax error not results. point of programme check string sequence, find specific substrings in , print resulting string having substring , 19 characters next it. print each time strings occurs , every resulting string.

here code..

x=raw_input('get string:: '); m=len(x); k=0; while(k<m): if('aat'in x or 'aac' in x or 'aag' in x): start = x.find('aat') or x.find('aac') or x.find('aag') end=start+19 print x[start:end]

when i'm inputting string atggaatcttgtgattgcattgacacgccatgccctggtgaagaactcttagtgaaatatcagtatatct. searches aat , prints resulting substring not aag , aac. can help me implement operator???

in example, it's improve utilize regular expression.

>>> text = 'atggaatcttgtgattgcattgacacgccatgccctggtgaagaactcttagtgaaatatcagtatatct' >>> re.search('(?:aa[tcg])(.{19})', text).group(1) 'cttgtgattgcattgacac'

you alter re.findall if multiple matches desired string. (but won't work if want on lapping matches (ie, string of 3 appears 1 time again in 19).

python operator-keyword

No comments:

Post a Comment