我很确定有一个常见的习惯用法,但我无法通过Google搜索找到它...
这是我想要做的(在Java中):
// Applies the predicate to all elements of the iterable, and returns
// true if all evaluated to true, otherwise false
boolean allTrue = Iterables.all(someIterable, somePredicate);
Run Code Online (Sandbox Code Playgroud)
这在Python中如何完成"Pythonic"?
如果我能得到这个答案也会很棒:
// Returns true if any of the elements return true for the predicate
boolean anyTrue = Iterables.any(someIterable, somePredicate);
Run Code Online (Sandbox Code Playgroud)
eum*_*iro 76
你的意思是:
allTrue = all(somePredicate(elem) for elem in someIterable)
anyTrue = any(somePredicate(elem) for elem in someIterable)
Run Code Online (Sandbox Code Playgroud)
allTrue = all(map(predicate, iterable))
anyTrue = any(map(predicate, iterable))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15869 次 |
| 最近记录: |