I'm getting a python syntax error for the following line of code:
orientations = [[(ants[0].loc, 0, {i: i for i in range(self.num_players)})]]
^
This is from someone else's script that I'm pretty sure should work, so I suspect the problem might be the version of python I'm using? I'm running python 2.6.6.
3 Answers 3
As others said, you have to use Python 2.7 if you want to make this syntax work.
Alternatively you can use tuples to initialize the dictionary:
[[(ants[0].loc, 0, dict((i, i) for i in range(self.num_players)))]]
But there might be other parts of the code that would have to be changed as well. It might be easier to upgrade to Python 2.7, especially if you work with someone else together who uses this version.
Comments
{i: i for i in range(self.num_players)}
in python 2.5.2 is:
dict( (i,i) for i in range(self.num_players) )
Comments
You are probably right. Seems to work for me with Python 2.7.