Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 2 vs 3: Lambda Operator [duplicate]

Has there been a change in the way lambda functions work between Python 2 and 3? I ran the code in python 2 and it works fine, but fails in Python 3 which I am trying to port my code into in order take advantage of a 3rd party module.

pos_io_tagged = map(lambda ((word, pos_tag), io_tag):
    (word, pos_tag, io_tag), zip(zip(words, pos_tags), io_tags))

I have researched multiple questions on Stackoverflow and read a couple of articles such as this but still can't find the answer. Is there any resources that I can view?

like image 657
plotplot Avatar asked Apr 01 '15 16:04

plotplot


1 Answers

Your problem is that you are using parentheses () with your lambda expression, which will confuse it. Try the following:

pos_io_tagged = map(lambda word, pos_tag, io_tag:
    (word, pos_tag, io_tag), zip(zip(words, pos_tags), io_tags))

Look here for more information.

like image 140
A.J. Uppal Avatar answered Nov 13 '22 14:11

A.J. Uppal