R
R
RedHairOnMyHead2016-01-08 21:56:03
Django
RedHairOnMyHead, 2016-01-08 21:56:03

How to read data from one line in Python 3?

Started learning Python and ran into a reading problem (working in PyCharm).
Is it possible to read data as from a single thread in C++?
Input data:
>>>3 4
>>>2 1 4
>>>3 1 3 1
>>>1 2
And immediately I want to calculate how many identical numbers (I just increment the elements equal to the number).
PS I would not like to write down the input data

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
throughtheether, 2016-01-08
@ThePyzhov

For version 2.7:

# вводим числа через пробел
data = raw_input()
# преобразуем символы в числа
data = map(int,data.split())
from collections import Counter
# подсчитываем, сколько раз встречается каждое значение
ctr = Counter(data)

When you enter
, we get ctr in this form:
Counter({4: 3, 1: 2, 2: 2, 3: 2, 5: 1})

M
Michael, 2016-01-08
@nextel

With each input, we push the entire sheet, after completing the input, we parse the sheet as we want, or am I not understanding something?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question