Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # longest_repeat_substring.py
- data = '''
- abcfpcompassionatenrzoujdqicbsexgvahltcpghsexbmkentrepreneurshipsfrnujwqiz
- ovaltdylcmkfenergeticztgsexbnwdyx123456789abchtrzujhqiwy123456789abcycpgml
- kfnbvasexdtrhzoncdqipmbygconversationalistsdwsexujlakfdplsexbhwnrymtkfqien
- trepreneurshipasgczoujvawtabcdefg0123456dmnlgkfyvaqihubrpczosexkfentrepren
- eurshipsaujphwlmzovaicrbtdsexgnylujsexccompassionateyrqinwgkfdtzovapmhbrde
- nergeticqrkfwczoujtynhqilbvapgmsexlwgbcompassionatetujsexmkfrcvzoyndpqihbv
- aypwlmjcdhtrqienergeticwrlngsexkfzodcgwbenergeticermrvatqikfnzomyhujplsexm
- hdpwgujvakzoyqicrbsexntlyvatwqiguj01234567890123456789sexkfhzobnrdprzosext
- cywmdhnlkfpvacompassionategujqimtvazohylsexkfpcujbdrgnqiwtzogpcvahujdmrwlb
- 01234567890123456789kfnsexzobrythqimvadcngentrepreneurshipssexwujpkltsexbn
- rd01234567890123456789mhlgcujqikfzowsexgujabnzoytldcqikfwmprhsextzohcompas
- sionatelrcypdgujvakfqimnwbczotqipysexdcompassionateqflnmghujrwvavaujqiplrz
- okfcompassionatehwdbmysextgncdyqignhrlmvatsexcpujcompassionatezokfbsexvacb
- nhlprdujenergeticarnwkftqygzomqitnujmgsexva01234567890123456789xyzbhrpkfwu
- jsexrclhmtdvankfqibywzenergetictrogpqigujkcompassionateflwhzoaprtnycmsexdb
- dysexzognkfctqenlightenmentimujvalwbhrlrvaenergeticyrpzokfcntbmhgujsexpqiy
- dwujsexblm01234567890123456789owkrdqicpnvagbdqigujhpmkfnrzoytvawcsexlcompa
- ssionatekenergeticurqfujsexbydtrmpcvahqinzolgwwvaykfbzodqilnrgsexyujentrep
- reneurshipsmphvarghydplzocentrepreneurshipskfsexqiwbmtnjlzotkfvagnyujhbent
- repreneurshipswpsexdrmqicrcpqmhdsexzoykfvalngenergeticirwtujbvaltmenergeti
- corzowpqiyhnbujrsexkfdcynqimclrpujvawsexdzokf01234567890123456789gpyclwhkf
- rzoabcdefg0123456tvagbnujqidsexmkfbwzovz123456789abcaqitpgnylsexhrujdchmse
- xygcompassionateujrptwczoqilvanbdkfmqilthybnk01234567890123456789ujcwsexva
- zodzodbqitsexwgnrhpvakfmujlenergeticrcyujlkfrcytnqisexhzocompassionatevwpg
- mbdvaqicompassionatewvawbpgrthlsexycovfujndmnvabwhenergeticvrkfujdglmqiyps
- extzocrvamzoqilrconversationalistseyujpkftgnsexdbhwcqidpbhlzovaentrepreneu
- rshipsgujkftnsexwrmyl01234567890123456789fdpqimgzotcnbysexvahwnujbhqi01234
- 567890123456789wdgvasexymcpzokfyuv123456789abcjnpgcvarmzohkftdlsexbqiqitbp
- hvansexzolycenergeticsrdrkfwmgujwthqirpzenlightenmentoujcvalndsexmgkfbpzog
- kfujmnqilrabcdefg0123456bdyhwvactsexywkfsexmqidvarzohupc012345678901234567
- 89bldentrepreneurshipsbujsextplrcqizowvaghkfbymnmujrkfbygsexdhzovapqilncom
- passionatexcwpujybldwckfsexvahqabcdefg0123456imzorgtnqprlcsexwmdvatzonujgk
- fhbyhentrepreneurshipsnujmbypwvatzokfdlqigsexrcdcqihzg01234567890123456789
- xyzrsexwlujmbthngbmultibillionairepsextywqizovalrcmudkfmghzosexqikfenerget
- icdrlntbrcdqihwglmcompassionatezujvatcysexbdnrkfytrnzosexvaujfgcqrgnhpackn
- owledgmentmujtwzosexlqicqilrconversationalistsfycgsexdkfpcompassionatenxyz
- '''
- print data
- data = data.strip()
- print '\n', len(data)
- def longest_seq(string,results,minlen=5,cutoff=2500):
- sss = string[:cutoff]
- d = sss[int(len(sss)*0.5):]
- longest=[]
- size=[]
- while len(d) > minlen:
- t=d=d[1:]
- while len(t) > minlen:
- if sss.count(t) > 1:
- for i in longest:
- if t in i: t='!'; break
- if t != '!':
- longest=sorted(longest+[t],key=len)
- longest=longest[-results:]
- size.append((data.count(t)*len(t),t))
- size=list(set(size))
- size=sorted(size)
- size=size[-results:]
- break
- t=t[:-1]
- return longest[::-1],size[::-1]
- data=''.join(data.split())
- LS,SZ=longest_seq(data,20,8)
- print '\nLen.: \tOccurs: \tTotal Size: \t\tData:'
- ts=0
- for i in LS:
- size = data.count(i)*len(i)
- ts += size
- print '%s\t%s\t\t%s\t\t%s' % (len(i), data.count(i), size, i)
- print '\n\nSize: \t\tData:'
- for i in SZ:
- print '%s\t\t%s' % (i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement