Skip to content

Commit 74e3af1

Browse files
committedDec 19, 2022
Bite 278 - from collections import Counter, most_common()
1 parent 316c1bb commit 74e3af1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎278/frequency.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from collections import Counter
2+
3+
4+
def major_n_minor(numbers):
5+
"""
6+
Input: an array with integer numbers
7+
Output: the majority and minority number
8+
"""
9+
numbers = Counter(numbers)
10+
# you code ...
11+
return numbers.most_common()[0][0], numbers.most_common()[-1][0]

‎278/test_frequency.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
from frequency import major_n_minor
4+
5+
6+
@pytest.mark.parametrize("data, expected", [
7+
([1, 2, 3, 2, 2, 2, 3], (2, 1)),
8+
([0, 0, 0, 1, 2, 2], (0, 1)),
9+
([9, 8, 7, 8, 8, 9], (8, 7)),
10+
([2, 0, 2, 0, 2, 1], (2, 1)),
11+
([1, 3, 5, 7, 8, 8, 9, 9, 3, 5, 8, 7], (8, 1)),
12+
([9, 0, 5, 7, 8, 8, 9, 0, 5, 9, 9, 5], (9, 7)),
13+
])
14+
def test_frequency(data, expected):
15+
assert major_n_minor(data) == expected

0 commit comments

Comments
 (0)
Please sign in to comment.