Hi everyone,
I am going through a self-paced class for Python beginners and have ran into a dictionary problem that I can't figure out. I'm creating a set of words from user input. Then send those words to a dictionary that adds a key for when the word is first used. My problem is the dictionary clears after every input although it is suppose to maintain the dictionary items. Could someone please point out where I am off?
while True:
text = input("Enter text: ")
for punc in ",?;.":
text = text.replace(punc, "")
words = {}
seen = set()
for word in text.lower().split():
size_seen = len(seen)
seen.add(word)
if len(seen) > size_seen:
words[word] = len(seen)
if text == "":
break
for word in words:
print(word, ":", words[word])
print("Finished")
Thanks for the help in advance