相當肯定有一個常見的成語,但無法與谷歌找到它..
這是我想做的事(在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