col1 = [2, 3, 6, 11, 19, 29, 32]
col2 = [48, 49, 57, 89, 120, 110, 105]
pd, nd, pi, ni = 0, 0, -1, -1
for i in range(len(col2)-1):
d = col2[i+1] - col2[i]
if d > 0 and d > pd:
pd, pi = d, i
if d < 0 and abs(d) > nd:
nd, ni = abs(d), i
print "Max positive difference :" + str(col1[pi+1])
print "Max negative difference :" + str(col1[ni+1])
给你:
输出:
^{pr2}$更新:短版
我想这就是你想要的
您可以在不过度使用局部变量、循环和条件的情况下尝试此操作:
相关问题 更多 >
编程相关推荐