Skip to content

Instantly share code, notes, and snippets.

@tylereaves
Last active December 29, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylereaves/7711302 to your computer and use it in GitHub Desktop.
Save tylereaves/7711302 to your computer and use it in GitHub Desktop.
import tables
import strutils
var words = initOrderedTable[string, int]()
var counts = initTable[int, int]()
for line in lines(stdin):
for word in split(line):
if words.hasKey(word):
let id = words[word]
counts[id] = counts[id] + 1
continue
let id = words.len
words[word] = id
counts[id] = 1
for pair in pairs(words):
echo (pair.val, "\t",counts[pair.val],"\t",pair.key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment