成对遍历列表或元组 [英] pairwise traversal of a list or tuple
本文介绍了成对遍历列表或元组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
a = [5, 66, 7, 8, 9, ...]
是否可以进行迭代而不是这样写?
Is it possible to make an iteration instead of writing like this?
a[1] - a[0]
a[2] - a[1]
a[3] - a[2]
a[4] - a[3]
...
谢谢你好!
推荐答案
当然。
for i in range(1, len(a)):
print a[i] - a[i-1]
我无法看到真正的问题在这里。您是否阅读了 python教程?
I fail to see what the real problem is here. Have you read the python tutorial?
这篇关于成对遍历列表或元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文