python脚本执行报错整理

people = [
{'name':'alex','age':1000},
{'name':'wuxie','age':100},
{'name':'wangcanghai','age':9000},
{'name':'zhangqiling','age':10000},
] print('df',max(people,key=lambda dic:dict['age']))

执行结果

D:\installPackage\python\python.exe D:/python/hsj/except/内置函数.py
Traceback (most recent call last):
File "D:/python/hsj/except/内置函数.py", line 27, in <module>
print('df',max(people,key=lambda dic:dict['age']))
File "D:/python/hsj/except/内置函数.py", line 27, in <lambda>
print('df',max(people,key=lambda dic:dict['age']))
TypeError: 'type' object is not subscriptable Process finished with exit code 1

检查原因为

print('df',max(people,key=lambda dic:dict['age']))-----》这段代码中dict输入不正确,更改为dic后执行正常
更改后结果
people = [
{'name':'alex','age':1000},
{'name':'wuxie','age':100},
{'name':'wangcanghai','age':9000},
{'name':'zhangqiling','age':10000},
] print('df',max(people,key=lambda dic:dic['age']))

  执行结果如下

D:\installPackage\python\python.exe D:/python/hsj/except/内置函数.py
df {'name': 'zhangqiling', 'age': 10000} Process finished with exit code 0

  

上一篇:Android 多线程通信 访问网络


下一篇:python在sqlite动态创建表源码