Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- text = "110111110111111001011101110011011011100001000001101001110011110100101110000010101000000111111111111111100001101110000100011101010110110111101100111101101111010111011101000000010011001010110101000110010101111010111101011100011110110110011010101111111011011001010011010100011001010011011011000000001111100111011011001000010111100000100010010110110001000110001101110101010110100010110000000111110001010110001100001111111110011001001011000110010110011000001101101110001010111101110000100100111111110101001100000111001101101001011101100010010111100110100101000001101000010101111110110111011111100100000110110011111100010000010010001111101101100101011111111111110111110001100101001001011110100110010010011111000110110101111100010001110110001001101110100011101010100011110110100000111011010110011110101001100010010010000000010010100010000000110110110001010001110110100111010111100110011010100111110000010011110101010110010000001000000010100111101001110010000001000010111101010010001010000101100000001000100001100100111101010100100111111100101010001011111101101111010111101000000111110001110011101010100100100010001001101111110000111110100101111100000101000100100100010111111001000100000110001101000110000101001101100000001101010000010001011101110110100110111010010111011010011000101000101100101110101001100111101101001111111100011011110110100111100100100001010010011011111010011110111010110111100111000101111010001101000001010111000011101100010011101001111101111110010011001011101100100011001010010110000100" # Ваш бинарный текст
- ngram_frequencies = {}
- # Перебираем n от 1 до 10
- for n in range(1, 11):
- ngrams_list = [text[i:i + n] for i in range(len(text) - n + 1)]
- ngram_frequency = Counter(ngrams_list)
- ngram_frequencies[n] = ngram_frequency
- for n, frequency in ngram_frequencies.items():
- print(f"n = {n}")
- sorted_frequency = frequency.most_common()
- for ngram, count in sorted_frequency:
- print(ngram, ";", count,";",f"{round((count/len(text)*100),2)}%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement