【发布时间】:2010-11-23 11:27:53
【问题描述】:
我有一个 Python 列表,我想检查是否有任何元素为负数。 Specman 具有用于列表的 has() 方法:
x: list of uint;
if (x.has(it < 0)) {
// do something
};
其中it 是一个 Specman 关键字,依次映射到列表的每个元素。
我觉得这很优雅。我查看了Python documentation 并找不到类似的东西。我能想到的最好的办法是:
if (True in [t < 0 for t in x]):
# do something
我觉得这很不雅。有没有更好的方法在 Python 中做到这一点?
【问题讨论】: