import collections def check(line, name): cnt = collections.Counter(line.lower().split()) with open(name, "w") as f: for word in sorted(cnt): f.write(f"{word} {cnt[word]}\n") return