Skip to content

Commit 6775b13

Browse files
committed
solved(python): programmers
- 해시 / 완주하지 못한 선수
1 parent 48c0546 commit 6775b13

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

programmers/python/해시/완주하지_못한_선수/__init__.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from collections import Counter
2+
from typing import List
3+
4+
5+
def solution(participant: List[str], completion: List[str]) -> str:
6+
counter = Counter(participant)
7+
8+
for name in completion:
9+
counter[name] -= 1
10+
11+
return counter.most_common()[0][0]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"params": [
4+
[
5+
"leo",
6+
"kiki",
7+
"eden"
8+
],
9+
[
10+
"eden",
11+
"kiki"
12+
]
13+
],
14+
"expected": "leo"
15+
},
16+
{
17+
"params": [
18+
[
19+
"marina",
20+
"josipa",
21+
"nikola",
22+
"vinko",
23+
"filipa"
24+
],
25+
[
26+
"josipa",
27+
"filipa",
28+
"marina",
29+
"nikola"
30+
]
31+
],
32+
"expected": "vinko"
33+
},
34+
{
35+
"params": [
36+
[
37+
"mislav",
38+
"stanko",
39+
"mislav",
40+
"ana"
41+
],
42+
[
43+
"stanko",
44+
"ana",
45+
"mislav"
46+
]
47+
],
48+
"expected": "mislav"
49+
}
50+
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import json
2+
import os
3+
import unittest
4+
5+
from parameterized import parameterized
6+
7+
from .main import solution
8+
9+
10+
def load_sample(filename: str):
11+
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
12+
13+
with open(path, "r") as file:
14+
return [(case["params"], case["expected"]) for case in json.load(file)]
15+
16+
17+
class TestCase(unittest.TestCase):
18+
@parameterized.expand(load_sample("sample.json"))
19+
def test_case(self, params: list, expected: any):
20+
# When
21+
result = solution(*params)
22+
23+
# Then
24+
self.assertEqual(expected, result)
25+
26+
27+
if __name__ == "__main__":
28+
unittest.main()

0 commit comments

Comments
 (0)