Python-通过嵌套循环循环打印项目(如果项目发生更改)
我正在循环几个嵌套的循环。如果第一个循环的项目发生变化,我想打印它。我该怎么做Python-通过嵌套循环循环打印项目(如果项目发生更改),python,nested-loops,Python,Nested Loops,我正在循环几个嵌套的循环。如果第一个循环的项目发生变化,我想打印它。我该怎么做 for slope in slopeList: for yarddist in yardDistList: for chiptreesperacre in chipAcreList: for chipvolpertree in chipVolList: f
for slope in slopeList:
for yarddist in yardDistList:
for chiptreesperacre in chipAcreList:
for chipvolpertree in chipVolList:
for smalllognumber in smallAcreList:
for smalltreevolpertree in smallVolList:
for largelogperacre in largeAcreList:
for largetreevolpertree in largeVolList:
data = [slope, yarddist, chiptreesperacre, chipvolpertree, smalllognumber, smalltreevolpertree, largelogperacre, largetreevolpertree]
if slope changes:
print data
存储以前看到的值,并进行比较:
previous_slope = None
for slope in as_many_loops_as_you_like:
data = [slope, other_stuff]
if slope != previous_slope:
print data
previous_slope = slope
可以将上一个_坡度添加到a,并在内部循环中添加后观察其长度:
slope = set()
slope.add(previous_slope)
old_length = len(slope)
for first_loop:
slope.add(current_slope)
if len(slope) > old_length:
print 'Changed!'
break
对每个内部循环重复此模式。您认为“it更改”是什么意思?它与上一次迭代中的值不同?循环中循环中循环中循环中循环中循环中循环中循环中循环系列?你还有什么建议?