함수 solution은 정수 n을 매개변수로 입력받습니다. n의 각 자릿수를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요. 예를들어 n이 118372면 873211을 리턴하면 됩니다.
code - 1차
def solution(n):
result = [i for i in str(n)]
result.sort()
result.reverse()
return int(''.join(result))
code - 2차
def solution(n):
result = sorted([s for s in str(n)], reverse=True)
return int(''.join(result))
https://github.com/seonmin5/codingtest_Python
GitHub - seonmin5/codingtest_Python
Contribute to seonmin5/codingtest_Python development by creating an account on GitHub.
github.com
반응형
'Python' 카테고리의 다른 글
[Python/level 0] 배열의 원소만큼 추가하기 - 181861 (1) | 2024.08.31 |
---|---|
[Python/level 0] 숫자 찾기 - 120904, enumerate (0) | 2024.08.31 |
[Python/level 0] 문자열 잘라서 정렬하기 - 181866, filter(function, iterable) (1) | 2024.08.31 |
[Python/level 0] 문자열 정렬하기 (2) - 120911, sorted (0) | 2024.08.31 |
[Python/level 0] 369게임 - 120891, str, count (0) | 2024.08.30 |