Ok, so this shouldn't be nearly this difficult, but I'm drawing a blank. So, the idea of this program is that it finds words that only occur in a text once, then capitalizes them. Here's the complete code:
from collections import Counter
from string import punctuation
path = input("Path to file: ")
with open(path) as f:
word_counts = Counter(word.strip(punctuation) for line in f for word in line.replace(")", " ").replace("(", " ")
.replace(":", " ").replace("", " ").split())
wordlist = open(path).read().replace("\n", " ").replace(")", " ").replace("(", " ").replace("", " ")
unique = [word for word, count in word_counts.items() if count == 1]
for word in unique:
text = wordlist
text.replace(word, str(word.upper()))
print(text)
It just prints the regular text, with no modifications made.
I know for a fact the first part works, It's just the final for loop thats giving me trouble.
Any idea what I'm screwing up?