[x for x, ...] 只是在使用 x 在某个数组上迭代时作为变量…
[x for x, ...]
x
x, count 捕获作为迭代值的两个项 c.items() .
x, count
c.items()
如果要打印以下结果: for _ in c.items(): print(_) 会打印出一个元组列表 (x, count) .
for _ in c.items(): print(_)
(x, count)
[x for x, count in c.items() if count > 2] 只是保存 X 在数组中使用 count 可作为过滤器使用。
[x for x, count in c.items() if count > 2]
X
count