python/알고리즘
[알고리즘] 백준 1427번, 소트인사이드 , 정렬하기, python(19)
incastle
2019. 4. 15. 01:19
문제
배열을 정렬하는 것은 쉽다. 수가 주어지면, 그 수의 각 자릿수를 내림차순으로 정렬해보자.
sorted라는 사기 스킬을 사용해서 너무 쉬워버렸다.
하지만 기본적인 함수가 생각이 안나서 검색 찬스를 사용함.
text = sorted(list(map(str, input())), reverse=True)
print(int("".join(text)))
생각이 안났던 부분은 "".join(변수)
list를 join하기~~
다른 사람의 코드
_ = sorted(input())[::-1]
print(''.join(_))
숏코드는 언제나 섹시하다.
여기서 내가 몰랐던 부분은
list[::-1] 이 부분!
https://stackoverflow.com/questions/9027862/what-does-listxy-do
What does list[x::y] do?
Possible Duplicate: Good Primer for Python Slice Notation I've been reading over some sample code lately and I've read quite a few websites but I just can't seem to get the query right to give...
stackoverflow.com
x[startAt:endBefore:skip]
첫 번째 콜런 전에는 start부분, 중간은 end before 세 번째는 skip
테스트 코드는 이러하다.