🐍
Python List Comprehension
파이썬 리스트 컴프리헨션으로 짝수 필터링 및 변환
DevNest
Python
PythonListComprehension
pythonPython List Comprehension
1# 0부터 9까지 짝수만 추출2evens = [x for x in range(10) if x % 2 == 0]3# [0, 2, 4, 6, 8]4 5# 짝수를 제곱6squared_evens = [x**2 for x in range(10) if x % 2 == 0]7# [0, 4, 16, 36, 64]