【发布时间】:2011-12-22 13:11:37
【问题描述】:
我有一个与python相关的代码理解问题:
def convex_hull(pts):
"""Returns the points on the convex hull of pts in CCW order."""
for m in (2 ** (2 ** t) for t in xrange(len(pts))):
hulls = [_graham_scan(pts[i:i + m]) for i in xrange(0, len(pts), m)]
//more code
我不知道这两个“for”应该如何工作。
遗憾的是,命令参考没有显示这样的用法示例,我无法确定它是否 - 真的 - 意味着一个 for 是另一个的左侧赋值?
此外,底部分配可能意味着什么? 'for' 语句是否返回值?!?!
感谢和抱歉初学者的问题。
【问题讨论】:
-
这个函数的第一行是一种非常可怕的编码风格。
for t in xrange(len(pts)): m = 2 ** 2 ** t更快、更短且更易于阅读。
标签: python syntax for-loop list-comprehension