3

In this message, the author has written

def neighbors((x, y)):

When I tried to run this with Python 3.3, it told me that it is invalid syntax. How do I solve the problem?

Community
  • 1
  • 1
MikkoP
  • 4,864
  • 16
  • 58
  • 106

2 Answers2

11

The solution is to do:

def neighbors(point):
    x, y = point

This feature was removed from 3.x, for a range of reasons.

Gareth Latty
  • 86,389
  • 17
  • 178
  • 183
  • 1
    Thanks! The quickest answer on StackOverflow I've ever seen. You need to wait a few minutes before I can accept it. – MikkoP Nov 11 '12 at 16:46
  • 1
    No worries! Just as a note, it's always worth waiting for a bit before accepting. You never know if someone will come along and give some insightful, amazing answer, which you might not get if you accept early and people stop looking at the question. In this case, I think I've covered it, but just a note. – Gareth Latty Nov 11 '12 at 16:47
0

Another option would be to write it as

def neighbors(x, y):

and replace:

for (nx, ny) in neighbors(path[-1]):

with

for (nx, ny) in neighbors(*path[-1]):
Eric
  • 95,302
  • 53
  • 242
  • 374