小编Jan*_*aml的帖子

for python中的循环(简单)

我有一个非常简单的问题,我很难与:)

我需要在python中以下三角矩阵的方式迭代元组列表


python代码

dataset = #list of truples

for i, left in enumerate(dataset):
  for j, right in enumerate(dataset):
    if j <= i : continue    #fixme there should be a better way
    foo(left,right)
Run Code Online (Sandbox Code Playgroud)

目标伪代码

for( i=0; i<size; i++ )
  for( j=i; j<size; j++ )
    foo(data[i],data[j])
Run Code Online (Sandbox Code Playgroud)

非常非常感谢你 :)

python iteration indexing loops for-loop

3
推荐指数
1
解决办法
396
查看次数

标签 统计

for-loop ×1

indexing ×1

iteration ×1

loops ×1

python ×1