목록listcomprehension (1)
IT 세계의 후아
[python]list comprehension, if-elif-else
※ list comprehension으로 다중 if문 쓰기for i in list: if 조건A: print("a") elif 조건B: print("b") else: print("c")≫ print(["a" if 조건A else "b" if 조건B else "c" for i in list]) # 프로그래머스 lv0 qr code# 초반 풀이def solution(q, r, code): return code[r-1::q] if r>0 else code[r::q-1] # ValueError: slice step cannot be zero # q=1, r=0일 때 오류! # 수정 후 return code[r::q] if r>0 else code if q..
Coding/Python
2024. 4. 24. 00:41