> 推导式指一种简明扼要的方法来创建列表/生成器/字典/集合的表达式。
列表推导式
print([i * i for i in range(20) if i % 3 == 0])
生成器推导式
g = (i for i in range(10))
for i in g:
print(i)
字典推导式
print({'key %s' % i: 'value %s' % i for i in range(1, 5)})
集合推导式
print({i ** 2 for i in range(1, 11)}) # 自带去重