如何将一个元素与排序列表中的下一个元素进行比较,并打印出它们之间的差异。任何帮助都将不胜感激。
Eg:
lst = [3.18,10.57,14.95,...]
10.57 - 3.18 = 7.39
14.95 - 10.57 = 4.38
...发布于 2011-05-29 09:00:44
你需要来自itertools的pairwise() recipe,很多Python的优点都来自于它。
>>> for x,y in pairwise(lst):
... print(y, " - ", x, " = ", y - x)
...
10.57 - 3.18 = 7.390000000000001
14.95 - 10.57 = 4.379999999999999https://stackoverflow.com/questions/6165277
复制相似问题