-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.py
36 lines (29 loc) · 2.87 KB
/
2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def FrequencyTable(Text, k):
freqMap = {}
n = len(Text)
print(f"n = {n}")
for i in range(n-k):
Pattern = Text[i:i+k] #← Text(i, k)
print(f"Pattern: {Pattern}")
if Pattern not in freqMap: #freqMap[Pattern] doesn't exist
freqMap[Pattern] = 1
else:
freqMap[Pattern] = freqMap[Pattern]+1
return freqMap
def BetterFrequentWords(Text, k):
FrequentPatterns = []
freqMap = FrequencyTable(Text, k)
# max ← MaxMap(freqMap)
maxVal = max(freqMap.values())
for Pattern in freqMap:
if freqMap[Pattern] == maxVal:
FrequentPatterns.append(Pattern)
return FrequentPatterns
# textSample = "TAGGTGCAGCCGAAGCTGAACTTCGTCGCGATTGCGTCTCAACTTTCACTAGGTGCAGCCGAAGCTGATAGGTGCAGGATTGCGTCTGATTGCGTCTCAACTTTCACGATTGCGTCTTAGGTGCAGCAACTTTCACTAGGTGCAGCCGAAGCTGAACTTCGTCGCACTTCGTCGCTAGGTGCAGCCGAAGCTGAGATTGCGTCTCCGAAGCTGACAACTTTCACGATTGCGTCTCCGAAGCTGACCGAAGCTGAACTTCGTCGCGATTGCGTCTACTTCGTCGCCAACTTTCACACTTCGTCGCCAACTTTCACGATTGCGTCTCCGAAGCTGACAACTTTCACCAACTTTCACCCGAAGCTGACCGAAGCTGACCGAAGCTGACAACTTTCACCAACTTTCACTAGGTGCAGGATTGCGTCTGATTGCGTCTCCGAAGCTGACCGAAGCTGAACTTCGTCGCGATTGCGTCTTAGGTGCAGACTTCGTCGCACTTCGTCGCGATTGCGTCTGATTGCGTCTACTTCGTCGCACTTCGTCGCTAGGTGCAGCCGAAGCTGACAACTTTCACTAGGTGCAGTAGGTGCAGGATTGCGTCTCCGAAGCTGAACTTCGTCGCTAGGTGCAGCCGAAGCTGATAGGTGCAGTAGGTGCAGACTTCGTCGCGATTGCGTCTACTTCGTCGCGATTGCGTCTGATTGCGTCTTAGGTGCAGGATTGCGTCTACTTCGTCGCGATTGCGTCTTAGGTGCAGCAACTTTCACCCGAAGCTGATAGGTGCAGACTTCGTCGCCAACTTTCACCAACTTTCACTAGGTGCAGTAGGTGCAGCAACTTTCACGATTGCGTCTACTTCGTCGCCCGAAGCTGACAACTTTCACCCGAAGCTGACAACTTTCACCAACTTTCACACTTCGTCGCTAGGTGCAGCAACTTTCACTAGGTGCAGTAGGTGCAGACTTCGTCGCACTTCGTCGCCCGAAGCTGA"
# tx = "atcaatgatcaacgtaagcttctaagcATGATCAAGgtgctcacacagtttatccacaacctgagtggatgacatcaagataggtcgttgtatctccttcctctcgtactctcatgaccacggaaagATGATCAAGagaggatgatttcttggccatatcgcaatgaatacttgtgacttgtgcttccaattgacatcttcagcgccatattgcgctggccaaggtgacggagcgggattacgaaagcatgatcatggctgttgttctgtttatcttgttttgactgagacttgttaggatagacggtttttcatcactgactagccaaagccttactctgcctgacatcgaccgtaaattgataatgaatttacatgcttccgcgacgatttacctcttgatcatcgatccgattgaagatcttcaattgttaattctcttgcctcgactcatagccatgatgagctcttgatcatgtttccttaaccctctattttttacggaagaATGATCAAGctgctgctcttgatcatcgtttc"
# o = BetterFrequentWords(tx, 9)
# print(o)
# for i in o: print(i)
print(BetterFrequentWords(Text='aactctatacctcctttttgtcgaatttgtgtgatttatagagaaaatcttattaactgaaactaaaatggtaggtttggtggtaggttttgtgtacattttgtagtatctgatttttaattacataccgtatattgtattaaattgacgaacaattgcatggaattgaatatatgcaaaacaaacctaccaccaaactctgtattgaccattttaggacaacttcagggtggtaggtttctgaagctctcatcaatagactattttagtctttacaaacaatattaccgttcagattcaagattctacaacgctgttttaatgggcgttgcagaaaacttaccacctaaaatccagtatccaagccgatttcagagaaacctaccacttacctaccacttacctaccacccgggtggtaagttgcagacattattaaaaacctcatcagaagcttgttcaaaaatttcaatactcgaaacctaccacctgcgtcccctattatttactactactaataatagcagtataattgatctga', k=9))
# if __name__ == "__main__":
# main()