How 2 compare words read by sys stdin sys in Python 3

+1 vote
How 2 Compare Words Read through sys.stdin.read()?

lets suppose take the words entered is : pasta, pasta, pasta, paratha, paratha

How 2 count Number of pasta and paratha in the entered string through sys.stdin.read() Please Help me in this
Jan 18, 2020 in Python by Alex
• 130 points
1,779 views

1 answer to this question.

+1 vote

Hi Alex,

You could use something like this:

import sys
pasta = 0
paratha = 0
print("Enter a string")
data = sys.stdin.readlines(1)
print(data)
for words in data:
    words = data.split(',')
for words in data:
    print(words)
    if words == 'pasta':
        pasta+=1
    else:
        paratha+=1

print(pasta)
print(paratha)
answered Jan 20, 2020 by Yamini

Related Questions In Python

–1 vote
2 answers
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 5, 2018 in Python by Omkar
• 69,220 points

edited Aug 8, 2018 by Omkar 8,149 views
0 votes
1 answer

In Python, how do I read a file line-by-line into a list?

with open(fname) as f:     content = f.readlines() # you ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,300 points
1,791 views
+3 votes
5 answers

How to read multiple data files in python

Firstly we will import pandas to read ...READ MORE

answered Apr 6, 2018 in Python by DeepCoder786
• 1,720 points
15,277 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

How to read a large file, line by line, in Python?

The correct, fully Pythonic way to read ...READ MORE

answered Jul 1, 2019 in Python by SDeb
• 13,300 points
868 views
0 votes
1 answer

How can I use the power function in python 2.7?

print(pow(3,4)) #this will return the exponentiation of 3 ...READ MORE

answered May 21, 2019 in Python by Mohammad
• 3,230 points
1,417 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP