SWEA
[SWEA] 1966. 숫자를 정렬하자 (Python/D2)
dev스카이
2023. 10. 31. 20:57
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
설명
주어진 N 길이의 숫자열을 오름차순으로 정렬한다.
풀이
정렬에 관한 내용 👇
[자료구조] sort, sorted, 정렬, 이중 리스트 정렬 (Python)
정렬 ✔ list.sort() - 오름차순으로 정렬 list = [3, 4, 2, 1, 5] list.sort() print(list) 출력 결과 [1, 2, 3, 4, 5] ✔ list.sort(reverse = True) - 내림차순으로 정렬 list = [3, 4, 2, 1, 5] list.sort(reverse=True) print(list) 출력 결
dev-cloud.tistory.com
Solution
t = int(input())
for i in range(1, t+1):
ans = 0
n = int(input())
num = list(map(int, input().split()))
ans = sorted(num)
print("#"+str(i),*ans)
num = []
※ ans앞에 *을 붙인 이유는 리스트에서 꺼내기 위함이다.