without haste but without rest
[python] 다중 조건으로 정렬하기 - lambda 본문
https://stackoverflow.com/questions/20145842/python-sorting-by-multiple-criteria
Python sorting by multiple criteria
I have a list where each element is of the form [list of integers, integer]. For example, an element of the list may look like this [[1,3,1,2], -1]. I want to sort a list containing the described...
stackoverflow.com
연습하기 좋은 문제
https://programmers.co.kr/learn/courses/30/lessons/12915
코딩테스트 연습 - 문자열 내 마음대로 정렬하기
문자열로 구성된 리스트 strings와, 정수 n이 주어졌을 때, 각 문자열의 인덱스 n번째 글자를 기준으로 오름차순 정렬하려 합니다. 예를 들어 strings가 ["sun", "bed", "car"]이고 n이 1이면 각 단어의 인덱
programmers.co.kr
n번째 문자로 정렬하되 n번째까지 전부 같으면 사전순으로 정렬한다.
고민좀 하다가.. n 번째 인덱스로 정렬하고 정렬 조건 후순위에 원래 문자열 자체를 주는 방법으로 해결할 수 있다는 것을 파악 함
def solution(strings: list, n):
strings.sort(key=lambda x: (x[n], x))
return strings
'ProgrammingLanguage > Python' 카테고리의 다른 글
[python] 비트마스크 기본 연산 정리 (0) | 2021.07.18 |
---|---|
[python] xor 연산자 ^= (0) | 2021.07.07 |
[python] 파이썬 이모지 보내기 (0) | 2021.06.23 |
슬랙 API 메세지 전송 템플릿 - python (0) | 2021.06.11 |
[python] csv 헤더 패스하기 (0) | 2021.05.11 |
Comments