Python列表返回语句破译
我在 python 例程中有以下语句:
return [hulls[h][i] for h, i in hull]
我无法弄清楚它实际返回的内容。
我的意思是,hulls 是一个 hull 列表,所以 'hulls[n]' 的类型是 'hull'。此外, hull 的类型为 'Point' hull 是一个点列表,但是
for h, i in hull?
文档没有提到为什么以及如何执行这样的调用,而且它闻起来像某种列表理解调用,但我仍然无法正确阅读该语法。
所以我希望帮助您理解如何用伪代码或 C# 翻译该句子,
非常感谢。
I have the following statement in a python routine:
return [hulls[h][i] for h, i in hull]
And I can't figure out what it does actually return.
I mean, hulls is a list of hull, so 'hulls[n]' is of type 'hull'. Additionally, hull is of type 'Point' hull is a list of points, but
for h, i in hull?
The docs don't mention why and how you can perform such a call, and it smells like some sort of list comprehension call, but I still can't read that syntax properly.
So I'd like help in understanding how you can translate the sentence in pseudocode, or c#
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这就是列表理解。您的 return 语句可以重写为不太紧凑:
Yes, it is list comprehension. Your return statement could be rewritten less compactly as:
船体看起来是一个二维的物体阵列。 Hull 是整数对 (x,y) 的列表。对于 Hull 中的每个坐标,它返回 hulls 中该位置的项目。
Hulls looks to be a two dimensional array of things. Hull is a list of pairs of ints (x,y). For each coordinate in Hull, it returns the item in hulls in that place.
是的,大卫是对的。如果你仍然对线路感到困惑
对于 h,i 在船体中:
我认为这意味着 hull 是一个包含多个元素的元组列表。因此,您使用 hull 中的每个元素作为 hull 的索引。
Yes, David is correct. If you're still confused about the line
for h, i in hull:
I think it means that hull is a list of tuples that have multiple elements. So you're using every element in hull to use as indices for hulls.