2015-04-01 41 views
1

lambda函數在Python 2和3之間的工作方式是否發生了變化?我在python 2中運行了代碼,它工作正常,但在Python 3中失敗,我試圖將代碼移植到第三方模塊中。Python 2 vs 3:Lambda運算符

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

我已經研究#2多個問題,並宣讀了幾個諸如this文章,但仍無法找到答案。有沒有我可以查看的資源?

+0

map()的返回值已經改變。 – 2015-04-01 16:07:53

+0

而且您可以使用參數分配的方式也已更改;拆包不再受支持。 – 2015-04-01 16:08:35

+0

查看http://www.diveintopython3.net/porting-code-to-python-3-with-2to3.html#tuple_params瞭解將元組傳遞給'lambda'函數的信息。 – MattDMo 2015-04-01 16:10:03

回答

2

你的問題是你在使用括號()和你的lambda表達式,這會混淆它。請嘗試以下操作:瞭解更多信息

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

here