1

I wrote a project in 2.7.9 and now have to port it to 2.4.3. I have a one-liner that is giving me syntax issues and am not sure what part of it does not comform to 2.4.3.

Code:

file = open(fileName, 'r')
header = [a for a in file.readline().split(',')]
data = [{x : y for x, y in zip(header, line.strip('\n').split(','))} for line in file] 

Error: =

data = [{x : y for x, y in zip(header, line.strip('\n').split(','))} for line in file]
                ^
SyntaxError: invalid syntax

`

user3281114
  • 187
  • 9

1 Answers1

4

There were no dictionary comprehensions in Python 2.4. They got introduced in Python 2.7.

You can rewrite

{x : y for x, y in zip(header, line.strip('\n').split(','))}

as

dict(zip(header, line.strip('\n').split(',')))
NPE
  • 486,780
  • 108
  • 951
  • 1,012