See also abs, zip and islice
from itertools import islice a = [1, 4 , 2 , 6 , 7, 3] result = [abs(p-q) for p, q in zip(a, islice(a, 1, None))] print result
Output:
[3, 2, 4, 1, 4]
from itertools import islice a = [1, 4 , 2 , 6 , 7, 3] result = [abs(p-q) for p, q in zip(a, islice(a, 1, None))] print result
[3, 2, 4, 1, 4]
0 comments:
Post a Comment