Ich möchte eine leere Liste in Python erstellen, damit ich später durch eine Funktion Elemente hinzufügen kann. Aber als ich versuchte, Elemente über die Funktion hinzuzufügen, zeigte es mir "TypeError: Kann Tuple-Objekt nicht implizit in str konvertieren". Warum bekomme ich das?Wie erstellt man eine leere Mutable-Liste in Python, damit das Listenelement später hinzugefügt werden kann?
page = "There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, " \
"or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't " \
"anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, " \
"making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence " \
"structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, " \
"or non-characteristic words etc."
find_word = "the"
word_positions = []
pos = 0
while page.find(find_word) != -1:
word_positions.append(page.find((find_word, pos)))
pos = pos + len(find_word)
print(word_positions)
'page.find ((find_word, pos))' Sie erhalten das, weil Sie ein Tupel an 'find' übergeben. – freakish