Solution :
def solution(data, ext, val_ext, sort_by):
if ext =='code':
ext=0
elif ext == 'date':
ext=1
elif ext == 'maximum':
ext=2
elif ext == 'remain':
ext=3
# val_ext 를 기준으로 추출하고
new=[]
for i in range(len(data)):
if val_ext > data[i][ext]: # val_ext보다 작은거만 추가함.
new.append(data[i])
# print(new)
# sort_by 로 정렬 함.
if sort_by =='code':
sort_t=0
elif sort_by == 'date':
sort_t=1
elif sort_by == 'maximum':
sort_t=2
elif sort_by == 'remain':
sort_t=3
new.sort(key = lambda x:x[sort_t],reverse=False) #오름차순
return new
Skills :
- 문자열의 인덱스를 찾고싶다 : index함수
(index 함수 (리스트, 튜플, 문자열) 에서만 사용 가능)
list = ["code", "date", "maximum", "remain"]
ext_idx = list.index(ext)
sort_idx = list.index(sort_by)
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] LV2 가장큰수 | 파이썬 (0) | 2025.05.12 |
---|---|
[프로그래머스] LV2 더 맵게 | 파이썬 (0) | 2025.05.07 |
[프로그래머스] LV2 주식가격 | 파이썬 (0) | 2025.05.07 |
[프로그래머스] LV2 기능개발 | 파이썬 (0) | 2025.05.07 |
[프로그래머스] LV2 프로세스 | 파이썬 (0) | 2025.05.07 |