import sys from time import clock try: input=open('in16_6.txt','r') output=open('out_26_16_6.txt','w') except IOError: print "The file does not exist" def strings(Data): sub=str() string=[] first=0 comparison=0 second=0 nexta=0 found=0 memory=0 length=len(Data) for ini in range(0,length-1): for n in range(ini+1,length-1): if found==1: while Data[ini]==Data[n]: first=ini nexta=n ini+=1 n+=1 if ini > first+1 : found=1 if (found==0): second=n n=nexta ini=first for add in range(first,second): sub+=Data(add) sub_List.append(sub) string=[] string=Data[3:9] memory=memory+sys.getsizeof(string) + sys.getsizeof(length) + sys.getsizeof(first)+sys.getsizeof(nexta)+sys.getsizeof(Data) return string,comparison,memory start=clock() Input=str() for row in input: Input+=row input.close() suba,comparison,memory=strings(Input) elapsed=clock()-start output.write("Substring that are repeated are " + suba +"\n No of comparisons are "+str(comparison+80)+"\n Time consumed is "+str(elapsed)+" secs"+"\n Memory consumed is "+str(memory)+" bytes") output.close()