Practice Note

Read input

Read a list of input

Ref: https://stackoverflow.com/questions/15963959/reading-a-line-of-integers-in-python

in python3:

1
numbers = list(map(int, input().split()))

Counter

collections.Counter()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
>>> from collections import Counter
>>>
>>> myList = [1,1,2,3,4,5,3,2,3,4,2,1,2,3]
>>> print Counter(myList)
Counter({2: 4, 3: 4, 1: 3, 4: 2, 5: 1})
>>>
>>> print Counter(myList).items()
[(1, 3), (2, 4), (3, 4), (4, 2), (5, 1)]
>>>
>>> print Counter(myList).keys()
[1, 2, 3, 4, 5]
>>>
>>> print Counter(myList).values()
[3, 4, 4, 2, 1]

# iterate the counter
for k, v in Counter(myList):
...