#!/bin/python3 import MyStripLib def Insert(word, words): found = False for item in words: if item[0] == word: found = True item[1] += 1 if not found: words.append([word,1]) f = open('ocap.txt') words = [] for line in f: for word in line.strip().split(): word = MyStripLib.MyStrip(word) if word != "" : Insert(word, words) for word in sorted(words): print (word[0], word[1])