dfile = open("abbreviations.txt", "r") dabbrev = dict() for line in dfile: line = line.strip() # print(line) words = line.split('\t') # print(words) dabbrev[words[0]] = words[1] ##dkeys = dabbrev.keys() ##for k in dkeys: ## print(k, "->", dabbrev[k]) infile = open("abbrev-input.txt", "r") for line in infile: # print(line) words = line.split() # print(words) for word in words: if word in dabbrev: print(dabbrev[word], end=' ') else: print(word, end=' ')