Amitabha@python 2019-09-17 16:01 采纳率: 0%
浏览 1592

TypeError: 'NoneType' object is not iterable到底时什么原因导致的,代码哪里有问题?已解决。

>>> values=list(range(1,11)).extend('Jack Queen King'.split(' '))
>>> suits='diamonds clubs hearts spades'.split(' ')
>>> deck=['%s of %s'%(v,s)for v in values for s in suits]
Traceback (most recent call last):
  File "<pyshell#42>", line 1, in <module>
    deck=['%s of %s'%(v,s)for v in values for s in suits]
**TypeError: 'NoneType' object is not iterable**
>>> values
>>> deck=['%s of %s'%(v,s)for v in list(range(1,11)).extend('Jack Queen King'.split(' ')) for s in 'diamonds clubs hearts spades'.split(' ')]
Traceback (most recent call last):
  File "<pyshell#44>", line 1, in <module>
    deck=['%s of %s'%(v,s)for v in list(range(1,11)).extend('Jack Queen King'.split(' ')) for s in 'diamonds clubs hearts spades'.split(' ')]
**TypeError: 'NoneType' object is not iterable**
>>> list3=list1
>>> list3
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ['Jack', 'Queen', 'King'], 'Jack', 'Queen', 'King']
>>> 'diamonds clubs hearts spades'.split(' ')
['diamonds', 'clubs', 'hearts', 'spades']
>>> deck1=[v for v in values]
Traceback (most recent call last):
  File "<pyshell#48>", line 1, in <module>
    deck1=[v for v in values]
**TypeError: 'NoneType' object is not iterable**

解决后的代码

>>> values=list(range(1,11))
>>> values
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> values.extend('Jack Queen King'.split(' '))#代码主要更改的部分
>>> values
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']
>>> suits='diamonds clubs hearts spades'.split(' ')
>>> suits
['diamonds', 'clubs', 'hearts', 'spades']
deck=['%s of %s'%(v,s)for v in values for s in suits]
>>> deck
['1 of diamonds', '1 of clubs', '1 of hearts', '1 of spades', '2 of diamonds', '2 of clubs', '2 of hearts', '2 of spades', '3 of diamonds', '3 of clubs', '3 of hearts', '3 of spades', '4 of diamonds', '4 of clubs', '4 of hearts', '4 of spades', '5 of diamonds', '5 of clubs', '5 of hearts', '5 of spades', '6 of diamonds', '6 of clubs', '6 of hearts', '6 of spades', '7 of diamonds', '7 of clubs', '7 of hearts', '7 of spades', '8 of diamonds', '8 of clubs', '8 of hearts', '8 of spades', '9 of diamonds', '9 of clubs', '9 of hearts', '9 of spades', '10 of diamonds', '10 of clubs', '10 of hearts', '10 of spades', 'Jack of diamonds', 'Jack of clubs', 'Jack of hearts', 'Jack of spades', 'Queen of diamonds', 'Queen of clubs', 'Queen of hearts', 'Queen of spades', 'King of diamonds', 'King of clubs', 'King of hearts', 'King of spades']
  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2019-09-18 19:17
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)