leo*_*leo 1 python list-comprehension
我有一个像这样的元组列表(但更大):
t = [(1, 2, 3), (4, 5, 6)]
Run Code Online (Sandbox Code Playgroud)
我想要一个包含每个元组的所有第一个元素的列表.我有:
first = list(x[0] for x in t)
Run Code Online (Sandbox Code Playgroud)
假设我只想在数字小于EPS的情况下添加"第一个"数字.我想要的是:
first = list(x[0] for x in t, x[0] < EPS)
Run Code Online (Sandbox Code Playgroud)
但这不是一个有效的python语句.
我想知道这样做的pythonic方式是什么(我可以像在Java/C++中那样做,但我认为必须有更好的方法.
| 归档时间: |
|
| 查看次数: |
288 次 |
| 最近记录: |