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:]))
More Related Contents:
- parser =3D syntax error [closed]
- Invalid syntax when trying to run python script [closed]
- Create a dictionary with comprehension
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape [duplicate]
- Why is there no tuple comprehension in Python?
- f-strings giving SyntaxError?
- Alternative to dict comprehension prior to Python 2.7
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Python cannot handle numbers string starting with 0. Why?
- SyntaxError: multiple statements found while compiling a single statement
- How can I use if/else in a dictionary comprehension?
- Is it possible to access current object while doing list/dict comprehension in Python?
- Python print statement “Syntax Error: invalid syntax” [duplicate]
- Nested dictionary comprehension python
- How to solve SyntaxError on autogenerated manage.py?
- Why can’t attribute names be Python keywords?
- Error “(unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape” [duplicate]
- Why doesn’t 2.__add__(3) work in Python?
- Why do I get the syntax error “SyntaxError: invalid syntax” in a line with perfectly valid syntax?
- Why am I getting “invalid syntax” from an f-string? [duplicate]
- Ampersand “&” syntax error running any Python script in VSCode?
- Why do parentheses in a lambda function cause syntax error on Python 3? [duplicate]
- Why does the IPython REPL tell me “SyntaxError: unexpected EOF while parsing” as I input the code?
- Invalid Syntax error when running python from inside Visual Studio Code
- Python: SyntaxError: keyword can’t be an expression
- “EOL while scanning single-quoted string”? (backslash in string) [duplicate]
- Python dictionary comprehension using locals() gives KeyError
- How to reuse an expression in a comprehension expression?
- Capture makes remaining patterns unreachable
- How to fix syntax error when printing a string with an apostrophe in it? [closed]