Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. file=open('pověst.txt','r')
  2. kniha=file.read()
  3. def tokenize():
  4.     if kniha is not None:
  5.         slova = kniha.lower().split()
  6.         return slova
  7.     else:
  8.         return None
  9.  
  10. def count_slova(tokens, token):
  11.     počet = 0
  12.  
  13.     for prvek in tokens:
  14.        
  15.         word = prvek.replace(",","")
  16.         word = word.replace(".","")
  17.  
  18.         if word == token:
  19.             počet += 1
  20.     return počet
  21.     
  22.     
  23.  
  24. slova=tokenize()
  25.  
  26. word='a'
  27. frequency=count_slova(slova, word)
  28. print('Frekvence slova "' + word + '" je: ' + str(frequency))
  29. input('Press ENTER to exit')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement