简体   繁体   English

TypeError:'NoneType'对象不可迭代:(

[英]TypeError: 'NoneType' object is not iterable :(

What i am trying to do is making a powerset by given set. 我正在尝试做的是根据给定的集合进行功率设置。 nums. But i am stuck in a problem right now. 但是我现在陷入了一个问题。 I can not understand why python just saying NoneType error... 我不明白为什么python只说NoneType错误...

+Q. + Q。 I am wondering if list_1 could interact with local list. 我想知道list_1是否可以与本地列表交互。 In my recursion func, i want to discribe 3th argument as list_ but doing like that occurs other problems. 在我的递归函数中,我想将第三个参数描述为list_,但是这样做会出现其他问题。 maybe process with list_ dont apply to real list list_1. list_的过程可能不适用于实际列表list_1。

def powerset(nums):
    list_1=[]
    recursion(0,nums,list_1)
    print (list_1)

def recursion(start,nums,list_1):
    if start>len(nums)-1:
        list_1.append([])
        return 0
    recursion(start+1,nums,list_1)
    i=0
    save_list=list_1
    save_len=len(list_1)
    while i<save_len:
        list_1.extend(save_list[i].append(nums[start]) )
        i += 1
def powerset(nums):
    list_1=[]
    recursion(0,nums,list_1)
    print (list_1)

def recursion(start,nums,list_):
    if start>len(nums)-1:
        list_.append([])
        return 0
    recursion(start+1,nums,list_)
    i=0
    save_list=list_
    save_len=len(list_)
    while i<save_len:
        listy=save_list[i]
        listy.append(nums[start])
        list_[i].extend(listy)
        i += 1

Try this. 尝试这个。 Your problem was with append as chepner said. 如chepner所说,您的问题与添加有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM