首页 > 解决方案 > How to unpack lambda tuple parameters to run on Python 3

问题描述

inflections[:, 1] = np.cumsum(inflections[:, 1])
optimalInflectionPoint = max(enumerate(inflections), key=lambda(idx, (s, v)): v)[0]

Above code throws an error in the following line when I try to run on Pyhton 3

optimalInflectionPoint = max(enumerate(inflections), key=lambda(idx, (s, v)): v)[0]

The description of the error, which is shown under lambda params :

tuple parameter unpacking is not supported in Python 3

How can I convert this tuple to run in Python 3 ? Please consider "inflections"..

Cheers,

标签: python-3.xlambdatuples

解决方案


Seems like optimalInflectionPoint = max(enumerate(inflections), key=lambda v: v[1][1])[0] would work. Just access the tuple element you want, you don't need to unpack.


推荐阅读