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
388 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
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 4, 2018 in Python by Omkar
• 69,030 points

edited Aug 8, 2018 by Omkar 4,511 views
0 votes
2 answers

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

readline function help to  read line in ...READ MORE

answered Jun 21 in Python by sahil
• 540 points
290 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
9,879 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 1,461 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
143 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,210 points
167 views