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 in Python by Alex
• 130 points
205 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 by Yamini

Related Questions In Python

0 votes
1 answer
+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 4, 2018 in Python by Omkar
• 69,060 points

edited Aug 8, 2018 by Omkar 3,297 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,250 points
198 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
7,081 views
+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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 939 views
0 votes
0 answers
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,250 points
86 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 20, 2019 in Python by Mohammad
• 3,230 points
104 views