Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. import tables, strutils
  2.  
  3. proc getFrequencies() : CountTable[string] =
  4. let wordFrequencies = initCountTable[string]() # <-- this should be var
  5.  
  6. for line in open("example1.nim").lines():
  7. for word in line.split(", "):
  8. wordFrequencies.inc(word)
  9.  
  10. return wordFrequencies
  11.  
  12. let wordFrequencies = getFrequencies()
  13. echo "The most frequent word is '", wordFrequencies.largest, "'"
  14. echo "The frequencies are '", wordFrequencies, "'"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement