Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- list
- slice
- 위코드
- SQL
- FOR
- STR
- DART
- range
- enumerate
- js
- iNT
- LOWER
- lambda
- Sorted
- and
- index
- count
- Python
- split
- or
- map
- len
- sum
- MAX
- Algorithm
- WECODE
- If
- 파이썬
- decorator
- join
Archives
- Today
- Total
코드로 우주평화
Total amount of points 본문
Description:
Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the collection.
For example: ["3:1", "2:2", "0:1", ...]
Write a function that takes such collection and counts the points of our team in the championship. Rules for counting points for each match:
- if x > y: 3 points
- if x < y: 0 point
- if x = y: 1 point
Notes:
- there are 10 matches in the championship
- 0 <= x <= 4
- 0 <= y <= 4
Solution:
1. games 배열에 담긴 요소를 꺼내고 매치 점수를 비교한다.
2. x가 크다면 3점, x가 작다면 0점, x와 y가 동점이라면 1점을 더한다.
3. 다 더한 점수를 반환한다.
def points(games):
return sum([{True:1,False:{True:3,False:0}[x>y]}[x==y] for x, _, y in games])
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
Student's Final Grade (0) | 2022.04.11 |
---|---|
Remove First and Last Character Part Two (0) | 2022.04.10 |
Transportation on vacation (0) | 2022.04.08 |
Beginner - Lost Without a Map (0) | 2022.04.07 |
Calculate average (0) | 2022.04.07 |