Is there a quick method to find the shortest repeated substring and how many times it occurs? If there is non you only need to return the actual string ( last case ).
>>> repeated('CTCTCTCTCTCTCTCTCTCTCTCT')
('CT', 12)
>>> repeated('GATCGATCGATCGATC')
('GATC', 4)
>>> repeated('GATCGATCGATCGATCG')
('GATCGATCGATCGATCG', 1)
Because some people think it's 'homework' I can show my efforts:
def repeated(sequentie):
string = ''
for i in sequentie:
if i not in string:
string += i
items = sequentie.count(string)
if items * len(string) == len(sequentie):
return (string, items)
else:
return (sequentie, 1)