Advertisement
selebry

dasdas

Nov 16th, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. from collections import Counter
  2. text = "11011111" # Ваш бинарный текст, вставь сюда свою строку из 1500 символов
  3.  
  4. ngram_frequencies = {}
  5.  
  6. # Перебираем n от 1 до 10
  7. for n in range(1, 11):
  8.  
  9. ngrams_list = [text[i:i + n] for i in range(len(text) - n + 1)]
  10. ngram_frequency = Counter(ngrams_list)
  11. ngram_frequencies[n] = ngram_frequency
  12.  
  13. for n, frequency in ngram_frequencies.items():
  14. print(f"n = {n}")
  15. sorted_frequency = frequency.most_common()
  16.  
  17. for ngram, count in sorted_frequency:
  18. print(ngram, ";", count,";",f"{round((count/len(text)*100),2)}%")
  19.  
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement