Python 可以用一行直接搞定,很简单。
import itertools
L = [1 ,2 ,3 ,4]
all(s <= t for s, t in itertools.pairwise(L))
内建的 all
方法,当所有的元素都为True时,才返回True。
all(L)
输出:
True
pairwise
可以将列表依次配对。
L = [1 ,2 ,3 ,4]
list(itertools.pairwise(L))
输出:
[(1, 2), (2, 3), (3, 4)]
Python 可以用一行直接搞定,很简单。
import itertools
L = [1 ,2 ,3 ,4]
all(s <= t for s, t in itertools.pairwise(L))
内建的 all
方法,当所有的元素都为True时,才返回True。
all(L)
输出:
True
pairwise
可以将列表依次配对。
L = [1 ,2 ,3 ,4]
list(itertools.pairwise(L))
输出:
[(1, 2), (2, 3), (3, 4)]
talentwill赞 1阅读 1.6k评论 1
风流倜傥的伤痕赞 1阅读 1.1k
遗失的美好灬阅读 5.4k
Swift社区赞 1阅读 614
代码的路赞 1阅读 1.8k
Exception阅读 2.9k
universe_king阅读 2.8k
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。