首页 > 编程语言 > 详细

python TypeError: 'NoneType' object is not iterable

时间:2017-06-27 20:33:40      阅读:6692      评论:0      收藏:0      [点我收藏+]

list(set(map(lambda tp_id : tp_id if not (‘#‘ in tp_id) and len(tp_id.strip().replace(‘\n‘, ‘‘)) > 0
else None, open(‘tp_list.txt‘).readlines()).sort()))

为了练习map,想着把一个循环写成一行代码。

结构跑程序时出了一个问题:TypeError: ‘NoneType‘ object is not iterable。

找了半天错误(写成一行代码在这时候真是作死)

发现是sort的问题, list的成员方法sort()将一个list排序(会改变list),但返回None。

None是不可迭代的。所以就报了这么一个错误。

python TypeError: 'NoneType' object is not iterable

原文:http://www.cnblogs.com/longwaytogo/p/7086911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!