python-3.x - 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,
解决方案
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.
推荐阅读
- email - 通过 Gmail API (Javascript) 发送电子邮件
- debugging - vscode launch.json 调试并打开特定的url
- php - Docker PHP/Nginx 环境无法处理带有反斜杠的文件夹路径
- javascript - React Js 特殊字符替换
- java - JFrame 窗口坐标错误
- angular - 仅在 VS2017 发布时出现角度错误
- jquery - 使用 JQuery 在 Bootstrap 中显示分页
- module - Verilog中使用generate的环形振荡器
- excel - 根据单元格颜色索引从一张表复制范围将部分范围粘贴到另一张表中
- google-sheets - 当单元格值在范围内时突出显示行