Invalid syntax using dict comprehension

Dict comprehensions are only available in Python 2.7 upwards. For earlier versions, you need the dict() constructor with a generator:

dict((x1, (x0,x2)) for (x0,x1,x2) in zip(x[:-2],x[1:-1],x[2:]))

Leave a Comment