Python Forum
sys.stdin to do a word count based on user entry
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sys.stdin to do a word count based on user entry
#1
Hi all

I have been using the sys module's stdinput to take input from the user until they enter the keyword 'submit'. Once this happens the dictionary would have stored the key:value pairs for what has been inputted up to this point.
The key:value pairs should print to the user.

The issue I am having is that I can't stop the std input with the keyword 'submit', curious why this is?

import sys
dictionary_words = {}
for line in sys.stdin:
    for word in line.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)
If its of any help, when I compile this py file, I run it in a linux terminal.

Much appreciated

P.S Unfortunately do have to use stdin :)
Reply


Messages In This Thread
sys.stdin to do a word count based on user entry - by Kaltex - Jul-19-2020, 09:34 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a menu and execute a function based on user selection in python? Thedarkphoenix 1 1,328 Nov-23-2022, 07:53 PM
Last Post: Larz60+
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,291 Nov-12-2022, 03:47 AM
Last Post: deanhystad
  Word count vanjoe198 1 1,976 Mar-16-2021, 12:27 AM
Last Post: BashBedlam
  Changing Directory based on user input paulmerton4pope 13 8,063 Aug-14-2020, 11:48 AM
Last Post: GOTO10
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,818 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  count unique letters in a word sunny_awesome 4 8,731 Jun-06-2019, 07:15 PM
Last Post: kotter
  Word based Game of 21 DatNerdKid 2 77,019 Aug-24-2018, 03:25 PM
Last Post: DuaneJack
  Count Letters in a Sentence (without using the Count Function) bhill 3 5,202 Jun-19-2018, 02:52 AM
Last Post: bhill

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020