a = [x * 2 for x in range(5)]
b = (x * 2 for x in range(5))
print('a=', a)
print('b=', b)
for t in range(2):
# Run Following Code Twice
print('----')
for i, x in enumerate(a):
print('a[{}]={}'.format(i, x))
print('----')
for i, x in enumerate(b):
print('b[{}]={}'.format(i, x))
Item 6: Generator Expression
Posted by Logan Chien