On Thu, Jun 29, 2006 at 01:06:54PM -0700, Matthew White wrote: > 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 >
And, if you need to search for a more complicated pattern, consider using the regular expression module (re): >>> import re >>> a = 'TCCCTGCGGCGCATGAGTGACTGGCGTATTTAGCCCGTCACATTTA' >>> pat = re.compile('ATTTA') >>> pat.findall(a) ['ATTTA', 'ATTTA'] >>> len(pat.findall(a)) 2 Dave [snip] -- Dave Kuhlman http://www.rexx.com/~dkuhlman _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor