相当肯定有一个常见的成语,但无法与谷歌找到它..
这是我想做的事(在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);
python中如何完成“pythonic”?
也将是巨大的,如果我能为这个获得答案,以及:
// Returns true if any of the elements return true for the predicate
boolean anyTrue = Iterables.any(someIterable, somePredicate);
这些形式也有“短路”的优势:'all'将终止于第一个'FALSE'发生,'any'将终止第一TRUE;发生。 – 2011-03-07 08:59:01
我是唯一一个认为这种常见操作无法接受的冗长的人吗? – cic 2015-06-11 20:30:58
欢迎来到Python @cic。 :D有椰子更适合FP http://coconut-lang.org/ – 2017-08-07 21:32:02