已有183人关注
lambda在二维数组中的使用
发表在Python图书答疑 2019-05-15 《Python从入门到项目实践》第3章 Python输入与输出
是否精华
版块置顶:
# 1.定义产品各项参数值,实现按参数名获得该参数值最高的一个产品型号
def searchMax(item):
    pro1={'product':'iphone xs','screen':5.8,'price':8699,'weight':'177克','depth':7.7}
    pro2={'product':'iphone xs Max','screen':6.5,'price':9599,'weight':'208克','depth':7.7}
    pro3={'product':'iphone xr','screen':6.1,'price':6499,'weight':'194克','depth':8.3}
    proList=[pro1,pro2,pro3]
    a=max(proList,key=lambda x:x[item])
    msg={'product':'产品','screen':'屏幕尺寸','price':'起价','weight':'重量','depth':'厚度'}
    print("您获取的参数信息是:",msg[item])
    return a

itemName=input("请输入要查找配置项最高的参数名称:")
productItem=searchMax(itemName)
print(productItem)
a=max(proList,key=lambda x:x[item])这段代码中key=lambda x:x[item]怎么理解?


2019-05-15 18:10:18编辑
分享到:
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照