凶狠蜡烛

文章
6
资源
0
加入时间
3年1月10天

TypeError: ‘int‘ object is not subscriptable

在使用python对字典排序时在该语句报错:# 按照键排序ll1=sorted(zi,key=lambda kv:(kv[0]))print(ll1)TypeError: ‘int’ object is not subscriptable原因为sorted()函数第一个参数不能为字典,而是zi.items():items() 函数以列表返回可遍历的(键, 值) 元组数组下标变量越界或者不支持下标访问的情况下会报这个错误。即对不可以相互操作的对象进行了操作或者是访问对象的方式不对。修改即可