일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- C++
- collections.deque
- 2750
- 파이썬머신러닝완벽가이드
- Sequential Search
- Numpy
- baekjun
- cpp
- almostIncreasingSequence
- markdown
- shapeArea
- codesignal
- 2015 봄학기 알고리즘
- til
- centuryFromYear
- 수 정렬하기
- 파이썬 포렌식
- 백준
- Counting cells in a blob
- data_structure
- 피보나치 수
- flask
- Daily Commit
- Python
- recursion
- codesingal
- 10953
- All Longest Strings
- adjacentElementsProduct
- matrixElementsSum
Archives
- Today
- Total
Introfor
Who likes it 본문
1
2
3
4
5
6
7
8
9
10
11
12
|
def likes(names):
if len(names) == 0:
return "no one likes this"
elif len(names) == 1:
return f'{names[0]} likes this'
elif len(names) == 2:
return f'{names[0]} and {names[1]} like this'
elif len(names) == 3:
return f'{names[0]}, {names[1]} and {names[2]} like this'
else:
num = len(names) - 2
return f'{names[0]}, {names[1]} and {num} others like this'
|
cs |
names의 크기에 따라서 출력값이 변하는 것을 고려해 조건을 나눠 출력했다.
1
2
3
4
5
6
7
8
9
|
def likes(names):
n = len(names)
return {
0: 'no one likes this',
1: '{} likes this',
2: '{} and {} like this',
3: '{}, {} and {} like this',
4: '{}, {} and {others} others like this'
}[min(4, n)].format(*names[:3], others=n-2)
|
cs |
다른 사람의 풀이인데 너무 잘 되어 있다. 이런 코드를 많이 봐야겠다..
'Programming_prob > Codewares' 카테고리의 다른 글
Persistent Bugger (0) | 2020.09.21 |
---|---|
Complementary DNA (0) | 2020.09.20 |
Descending Order (0) | 2020.09.20 |
Comments