标题: TypeError: object of type 'NoneType' has no len() [打印本页] 作者: kenima 时间: 2017-4-8 23:53 标题: TypeError: object of type 'NoneType' has no len() 各位大佬帮个忙,困扰好几天了,我试着编一个关于全排列的小代码,可是老是显示TypeError: object of type 'NoneType' has no len(),很尴尬。具体报错信息为:Traceback (most recent call last):
File "C:\Users\asus\Desktop\Exercise\00000.py", line 19, in <module>
arrange(member)
File "C:\Users\asus\Desktop\Exercise\00000.py", line 10, in arrange
temp_arrange = arrange(temp_list)
File "C:\Users\asus\Desktop\Exercise\00000.py", line 2, in arrange
if len(member) == 1:
TypeError: object of type 'NoneType' has no len()
我的思路是这样的:想用递归(或者迭代?)的方式:首先对于输入进的n个元素,转化为字符类型存放于列表中,在取出第一个字符类型作为插入元素,依次插入到前面n-1个已经做好全排列的结果中,最后以列表形式输出。预计的结果大概像这样:[['a','s','d'],['a','d','s'],['d','s','a'],['d','a','s']]
下面贴我的代码:
def arrange(member):
if len(member) == 1:
result = []
result.append(member)
print(result)
else:
x = member[0]
temp_list = member.remove(x)
temp_arrange = arrange(temp_list)
for i in temp_arange:
for j in range(len(i)):
i.insert(j,x)
print(i)
member = input("请输入待排列元素:")
member = list(member)
arrange(member) 作者: unkownY 时间: 2017-4-9 11:29
你用的是2还是3 作者: crossin先生 时间: 2017-4-9 13:45
报错里已经把你出错的地方都写出来了