문제 링크
https://programmers.co.kr/learn/courses/30/lessons/12915
문제 설명
문자열을 담은 리스트 strings와 정렬의 기준이 될 인덱스 n이 주어지면, 각 문자열의 n번 문자를 기준으로 정렬된 리스트를 반환해라
def solution(strings, n):
#answer = strings.sort(key = lambda x : x[n])
answer = sorted(strings,key=lambda x: (x[n],x)
return answer
- 새로 알게된 점
- list.sort() -> 새로운 리스트를 만들어주는 것이 아니라 리스트를 정렬만 해줌
- sorted() -> 새로운 리스트를 만들어준다.
'코딩 > 파이썬' 카테고리의 다른 글
[python]연결리스트 뒤집기 (0) | 2023.07.18 |
---|---|
[프로그래머스] 두 개 뽑아서 더하기 (0) | 2023.07.17 |
[Python] Unindent amount does not match previous indentPylance 에러 (0) | 2023.07.17 |
[python]딕셔너리에서 value값이 가장 큰 key 알아내는 (0) | 2023.07.15 |
프로그래머스 숫자 문자열과 영단어 파이썬 딕셔너리와 for문 (0) | 2023.07.15 |