-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_odd_int.py
More file actions
61 lines (50 loc) · 1.42 KB
/
find_odd_int.py
File metadata and controls
61 lines (50 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from collections import Counter
from collections import defaultdict
from typing import List
import pytest
from utilities import get_random_list
from utilities import timeit
@timeit
def find_odd_int_default_dict(input_ints: List) -> int:
d = defaultdict(int)
for integer in input_ints:
d[integer] += 1
for k, v in d.items():
if v % 2 == 1:
return k
@timeit
def find_odd_int_counter(input_ints: List) -> int:
counter = Counter(input_ints)
for item, count in counter.items():
if count % 2 == 1:
return int(item)
@pytest.mark.parametrize(
"input_list, result",
[
(get_random_list(min_value=5, max_value=5) + [7, 7, 7], 7),
(
get_random_list(min_value=5, max_value=5)
+ get_random_list(min_value=8, max_value=8)
+ [99],
99,
),
],
ids=["case_1", "case_2"],
)
def test_find_odd_int(input_list, result):
assert find_odd_int_default_dict(input_list) == result
@pytest.mark.parametrize(
"input_list, result",
[
(get_random_list(min_value=5, max_value=5) + [7, 7, 7], 7),
(
get_random_list(min_value=5, max_value=5)
+ get_random_list(min_value=8, max_value=8)
+ [99],
99,
),
],
ids=["case_1", "case_2"],
)
def test_find_odd_counter(input_list, result):
assert find_odd_int_counter(input_list) == result