什么时候应该使用生成器表达式?什么时候应该在Python中使用列表推导?
# Generator expression
(x*2 for x in range(256))
# List comprehension
[x*2 for x in range(256)]
Run Code Online (Sandbox Code Playgroud) foo = [x for x in bar if x.occupants > 1]
Run Code Online (Sandbox Code Playgroud)
谷歌搜索和搜索后,无法弄清楚这是做什么的.也许我没有找到合适的东西但是在这里.非常感谢任何改写这种速记的输入.