Jul-19-2020, 10:28 AM
(Jul-19-2020, 09:44 AM)DPaul Wrote: You may try to .strip() any non-printable chars from word,
before you test it. You never know.
Paul
hmm :( I added .strip() in the for loop, but still no good... when I type "submit" it just keeps accepting standard input and does not break the loop..
import sys dictionary_words = {} for line in sys.stdin: for word in line.strip().split(): if word == 'submit': break else: dictionary_words[word] = dictionary_words.get(word,0) + 1 for key,value in dictionary_words.items(): print(key,value)Am I right in doing a nested for loop, since I have to capture whats in the stdin first and then break up each line by words?