鱼C论坛

 找回密码
 立即注册
查看: 2700|回复: 2

[已解决]程序出现'NoneType' object is not iterable错误

[复制链接]
发表于 2022-9-19 21:21:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
下面是代码:
  1. num_list = input("please:").split(" ")
  2. zi = {}
  3. for i in num_list:
  4.     if i in zi:
  5.         zi[i] = zi[i]+1
  6.     else:
  7.         zi[i] = 1
  8. list_2 = list(zip(zi.values(),zi.keys()))# 将字典化为元组

  9. print(list(zip(zi.values(),zi.keys())),end='')
  10. list_3 = list_2.sort()  # 将list_2按照值进行排序
  11. print(list_3)
  12. c = dict(list_3)
  13. print(c)
  14. # for j in list_3:
  15. #     print(j)
复制代码

错误提示:
  1. Traceback (most recent call last):
  2.   File "e:\code_test\python100\62.py", line 13, in <module>
  3.     c = dict(list_3)
  4. TypeError: 'NoneType' object is not iterable
复制代码

已经在网上搜了,没找到合适的解答,麻烦各位了
最佳答案
2022-9-19 21:37:37
参考 docs.python.org/3/tutorial/datastructures.html?highlight=sort
list.sort 的返回值是?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-9-19 21:37:37 | 显示全部楼层    本楼为最佳答案   
参考 docs.python.org/3/tutorial/datastructures.html?highlight=sort
list.sort 的返回值是?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-9-19 22:20:40 | 显示全部楼层
dolly_yos2 发表于 2022-9-19 21:37
参考 docs.python.org/3/tutorial/datastructures.html?highlight=sort
list.sort 的返回值是?

谢谢了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-26 18:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表