# Collection of code snippets by Arne Vajhøj 
# (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import sys
import re

count = {}
for line in open(sys.argv[1], 'rt', encoding='utf-8'):
    for word in re.split('[^a-z\u00E0-\u00FF]+', line.lower()):
        if len(word) > 0:
            count[word] = count.get(word, 0) + 1
for e in sorted(count.items(), key=lambda itm:itm[1], reverse=True)[0:int(sys.argv[2])]:
    print('%s : %d' % (e[0],e[1]))
