Python:TypeError:未绑定方法list.copy()需要一个参数



给定一个类中的以下方法(抱歉名称是德语的(,但主要问题是为什么我在用liste_links = self.listeEntfernen(self.gewichte, list[x])调用方法listeEntfernen时会出错。我得到错误:TypeError:未绑定方法列表。copy((需要一个参数。我已经尝试过切换和删除self关键字,并尝试从类中调用函数,但不明白为什么它不在listeEntfernen()方法中使用list[x]作为liste2的参数。

def linkeSeite(self, ziel):
erg_links = []
erg_rechts = []
laenge_k_rechts = 1
laenge_k_links = 1
while not erg_rechts:
komb_rechts = itertools.combinations(self.gewichte, laenge_k_rechts)
if laenge_k_rechts > len(self.gewichte) or ziel > sum(self.gewichte):
return
for x in komb_rechts:
if sum(x) <= ziel:
continue
while not erg_links:
liste_links = self.listeEntfernen(self.gewichte, list[x])
komb_links = itertools.combinations(liste_links, laenge_k_links)
if (sum(x) - ziel) in liste_links:
erg_links = sum(x) - ziel
erg_rechts = x
break
for y in komb_links:
if sum(x) - ziel == sum(y):
erg_links = y
erg_rechts = x
break
laenge_k_links += 1
laenge_k_rechts += 1
return [erg_links, erg_rechts]
def listeEntfernen(self, liste1, liste2):
erg_liste = []
liste2_kopie = liste2.copy()
for i in liste1:
if i not in liste2_kopie:
erg_liste.append(i)
continue
liste2_kopie.remove(i)
return erg_liste

不清楚list[x]的目的是什么。您没有变量list,所以list仍然内置在对象中,所以可能是您想要的list(x)

最新更新