sort # 복수의 값으로 정렬할 때
세가지 이상의 값으로 이루어진 list 또는 튜플이 있을 때, 첫번째 값으로 먼저 정렬, 두번째 값으로 그 다음 정렬, 세번째 값으로 정렬을 순차적으로 적용하려면 sample_list = [(1,2,3), (2,5,3), (2,5,1), (2, 3, 10)] sample_list.sort(key=lambda x: [x[0], x[1], x[2]]) sample_list.sort(key=lambda x: [x[0], x[1], x[2]], reverse=True) # 전체가 뒤집힌다. # x[0] 기준으로는 오름차순 (default) # x[1] 기준으로는 내림차순으로 정렬하고 싶다면 sample_list.sort(key=lambda x: [x[0], -x[1]])
Javascript: Array for loop showing elements
Array의 요소들을 for loop를 돌면서 표현 const sampleArray = [1, 2 , 3, 'a' ,'b' ,'c']; for (const ele of sampleArray){ console.log(ele); }; ele of sampleArray of 입니다. in이 아니라 in 으로 하면 0,1,2,3,4,5 로 출력