[ ํํ์ for ํญ๋ชฉ in ๋ฆฌ์คํธ or ํํ if ์กฐ๊ฑด๋ฌธ ]
Python
๋ณต์ฌ
list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
# ๋ฆฌ์คํธ ์์์ for ๋ฌธ ์ฌ์ฉํ๊ธฐ 1
list = [ num * 3 for num in list ]
print(list)
Python
๋ณต์ฌ
list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
# ๋ฆฌ์คํธ ์์์ for ๋ฌธ ์ฌ์ฉํ๊ธฐ 2: if ๋ฌธ ์ฌ์ฉ
list = [ num * 3 for num in list if num % 2 == 1 ]
print(list)
Python
๋ณต์ฌ
# ๋ฆฌ์คํธ ์์์ for ๋ฌธ ์ฌ์ฉํ๊ธฐ 3: ๋ ๊ฐ ์ด์์ for ๋ฌธ
list = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
list = [ num * num2 for num in list if num % 2 == 1
for num2 in list if num2 % 2 == 1 ]
print(list)
Python
๋ณต์ฌ
# ๋ฆฌ์คํธ ์์์ for ๋ฌธ ์ฌ์ฉํ๊ธฐ 4: range() ๋ฉ์๋ ํ์ฉ
list = [ x * y for x in range(2, 20)
for y in range(1, 20) ]
print(list)
Python
๋ณต์ฌ