Advertisement
selebry

sdadas

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