I am running Eclipse SDK v3.6 with PyDev v2.6 plugin on two PC, with Linux and Windows.
I would like to pass a tuple as an argument, like (just example):
foo = lambda (x,y): (y,x)
print (foo((1,2)))
This works on Linux and gives the result:
(2,1)
On Windows it rises an error:
foo = lambda (x,y): (y,x)
^
SyntaxError: invalid syntax
How to solve the problem?
Thanks in advance...
Solution
Thanks to interjay and his reference to PEP 3113 I found that a tuple parameter is deprecated from 3.0 version of Python.
So, the code which did not worked and looked as
accepts = filter(lambda q1, q2: (q1, q2) in states, [(q1, q2) for q1 in D1.accepts for q2 in D2.accepts])
now works on both version 2.7 and version 3.0 of Python and looks as
accepts = filter(lambda q: (q1, q2) in states, [(q1, q2) for q1 in D1.accepts for q2 in D2.accepts])
where accepts is a list of tupes anyway.
解决方案
You are probably running Python 3.x on Windows, and Python 2.x on Linux. The ability to unpack tuple parameters was removed in Python 3: See PEP 3113.
You can manually unpack the tuple instead, which would work on both Python 2.x and 3.x:
foo = lambda xy: (xy[1],xy[0])
Or:
def foo(xy):
x,y = xy
return (y,x)