from collections import Counter def check(line, file): words = line.lower().split(" ") counter = Counter(words) with open(file, "w") as file: for i in sorted(counter): file.write(f"{i} {counter[i]}\n") return