列表或元组的成对遍历
问题描述
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?
相关文章