TypeError: kann nur concatenate list (not "tuple") to list ((Python -))

Beim ausführen von den folgenden code in ein kleines script, bekomme ich die folgende Fehlermeldung:

Traceback (most recent call last):
  File "/Users/PeterVanvoorden/Documents/GroepT/Thesis/f_python_standalone/python_files/Working_Files/testcase.py", line 9, in <module>
    permutations_01.determin_all_permutations()
  File "/Users/PeterVanvoorden/Documents/GroepT/Thesis/f_python_standalone/python_files/Working_Files/permutations_01.py", line 8, in determin_all_permutations
    config.permutations = [[1] + x for x in config.permutations]
TypeError: can only concatenate list (not "tuple") to list

Code:

import itertools
import config

def determin_all_permutations():
    L = list(xrange(config.number))
    List = [x+2 for x in L]
    config.permutations = list(itertools.permutations(List,config.number))
    config.permutations = [[1] + x for x in config.permutations]


def determin_lowest_price_permutation():
    length = len(L)
    a = 1
    while a <= length:
        point_a = L[a]
        point_b = L[a+1]

# Array with data cost connecting properties will exist of:
# * first column = ID first property [0]
# * second column = ID second property [1]
# * third column = distance between two properties [2]
# * forth column = estimated cost [3]

        position  = 0
        TF = False

        if TF == False:
            if point_a == config.properties_array[position][0] and point_b == config.properties_array[position][1] and TF == False:
                config.current_price = config.current_price + config.properties_array[position][3]
                config.current_path = config.current_path + [config.properties_array[position][2]]
                TF = True

            else:
                position += 1

        else:
            position = 0
            TF = False

Verstehe ich nicht, warum dieser Fehler Auftritt. Wenn ich test-Linie 8

config.permutations = [[1] + x for x in config.permutations]

in einer normalen situation, indem Sie eine Liste in der Schale, die für die ex:

List = [1,1,1],[1,1,1]
([1,1,1],[1,1,1])
List = [[0] + x for x in List]
List
([0,1,1,1],[0,1,1,1])

es funktioniert, aber bei Verwendung der exakt gleiche code in einer Methode, erhalte ich die Fehlermeldung über das hinzufügen von ein Tupel... Ist das nicht [1] eine Liste?

Kann mir jemand helfen?

Dank!

  • Bitte geben Sie den Treiber-code, den Sie verwenden, um den Fehler zu erzeugen. Sie haben derzeit die Funktion nur Definitionen, damit Ihr Beispiel ist nicht reproduzierbar, wie es ist.
Schreibe einen Kommentar