考虑以下代码:
l=[21,23,25,30,33,45,56,67,70,77--------------------]
h=35
r1=[]; r2=[]
for i in range(len(l)):
if(l[i] < h):
r1.append(l[i])
else:
r2.append(l[i])
print r1
print r2
得到的结果是:
[21, 23, 25, 30, 33]
[45, 56, 67, 70, 77----------------------]
现在我需要增加 h=35 以便当它达到 46 时,它的输出必须是
[21, 23, 25, 30, 33,45]
[56, 67, 70, 77----------------------]
接下来当 h 达到 57
[21, 23, 25, 30, 33,45,56]
[67, 70, 77-------------------------]
所以作为一个整体,最终结果应该显示:
[21, 23, 25, 30, 33]
[45, 56, 67, 70, 77-----------------]
[21, 23, 25, 30, 33,45]
[56, 67, 70, 77---------------]
[21, 23, 25, 30, 33,45,56]
[67, 70, 77--------------]
[21, 23, 25, 30, 33,45,56,67]
[70, 77--------------]
[21, 23, 25, 30, 33,45,56,67,70]
[77--------------]
[21, 23, 25, 30, 33,45,56,67,70,77]
[-----------------------]
什么会在 python 中产生这样的结果而不将它作为函数参数传递?任何人都可以建议它的代码......