1

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.

asked Jul 4, 2011 at 21:04
0

3 Answers 3

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.

answered Jul 4, 2011 at 21:11
Sign up to request clarification or add additional context in comments.

Comments

2
{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) )
answered Jul 4, 2011 at 21:11

Comments

0

You are probably right. Seems to work for me with Python 2.7.

answered Jul 4, 2011 at 21:11

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.