pythonlistmethodsargumentsunbound

Python: TypeError: unbound method list.copy() needs an argument


Given the following methods from a class (sorry the names are in german), but the main question is why do I get an error when calling the method listeEntfernen with liste_links = self.listeEntfernen(self.gewichte, list[x]). I get the Error: TypeError: unbound method list.copy() needs an argument. I've already tried switching and removing the self keyword and tried calling the function from the class but don't understand why it won't use list[x] as a parameter for liste2 in the listeEntfernen() method.

   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

Solution

  • It is not clear what is purpose of list[x]. You do not have your variable list, so is list still built in object, so then may be that you intend list(x).