squares =[]
for x in range(10):
if x%2 == 0:
squares.append(x**2)
이 코드를 함축하면,
squares = [x**2 for x in range(10) if x%2 == 0]
prices=[120, 345, 654, 768, -234]
mprices = []
for i in prices:
if i > 0:
mprices.append(i)
else:
mprice.append(0)
이 코드를 함축하면,
prices=[120, 345, 654, 768, -234]
mprices = [i if i>0 else 0 for i in prices]
numbers = []
for x in ['a', 'b', 'c']:
for y in ['x', 'y', 'z']:
numbers.append(x+y)
이 코드를 함축하면,
numbers = [x+y, for x in ['a', 'b', 'c'] for y in ['x', 'y', 'z']]