Hello Appu, You can use the count() method to find the number of occurances of a substring within a string:
>>> a = 'TCCCTGCGGCGCATGAGTGACTGGCGTATTTAGCCCGTCACATTTA' >>> a.count('ATTTA') 2 -mtw On Thu, Jun 29, 2006 at 12:45:06PM -0700, Apparao Anakapalli ([EMAIL PROTECTED]) wrote: > hello all: > > I have a question and I do not know how I can work it > out. > > > I have a file of sequences > >a > TCCCTGCGGCGCATGAGTGACTGGCGTATTTAGCCCGTCACATTTA' > >b > CCTGCGGCGCATGAGTGACTGGCGTATTTAGCCCGTCACAATTTAA' > .... > > (10 K) > > > pattern = 'ATTTA' > > I want to find the pattern in the sequence and count. > > For instance in 'a' there are two 'ATTTA's. > > How can I do that. > > One approach tried: > import re > > pat = 'ATTTA' > if re.search(pat,a): > print 'yes' > > By counting number of yeses I thought I can answer the > question. However, the above approach only looks for > the first instance of pat and says yes and moves to > next. > > > The other way: > a.find(pat) > > This also looks for first one and reports the position > of chracter. > > > Could any one suggest the best way to cound the number > of patterns. > > > Thank you > appu > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor