了解涉及最小功能的列表理解
我对list理解
非常精通。
但是,我无法理解以下语句:
min((-len(list), list[-1] - list[0] + 1) for list in [[0, 4], [1, 2]])[1]
我只了解[[0,4],[1,2]] 中的列表的部分,其中我们正在迭代列表。
I am well-versed with list comprehension
.
However, I am not able to understand the below statement:
min((-len(list), list[-1] - list[0] + 1) for list in [[0, 4], [1, 2]])[1]
I only understand the portion for list in [[0, 4], [1, 2]]
wherein we are iterating the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,<代码>列表将依次是
[0,4]
和[1,2]
。对于第一个,元组将为(-2,5)
(5 == 4-0 + 1),在第二个,元组将为(-2) ,2)
(2 == 2-1 + 1)。其中最小的是(-2,2)
,所以这就是返回的。因此,这试图找到最长的订订符,并将返回第一个元素和大小列表的最后一个元素之间的最小差异。
So,
list
is going to be, in turn,[0,4]
, and[1,2]
. For the first, the tuple is going to be(-2, 5)
(5 == 4 - 0 + 1), for the second, the tuple is going to be(-2, 2)
(2 == 2 - 1 + 1). The smallest of those is(-2,2)
, so that's what will be returned.So, this is trying to find the longest sublists, and will return the smallest difference between the first element and the last element of the lists that size.
它等同于以下代码段:
It's equivalent to the following code snippet: