Jul-01-2021, 01:46 PM
What do you think should happen when you append a list to a list? Did you think it would make the original list longer? Append (and insert) treat the argument as an object, not an iterable. From the docs:
Lists are important in Python. You need to REALLY understand how they work or it is going to come back to bite you again and again.
Quote:list.append(x)You could use extend to add items from a list to an existing list.
Add an item to the end of the list. Equivalent to a[len(a):] = [x].
Output:list.extend(iterable)
Extend the list by appending all the items from the iterable. Equivalent to a[len(a):] = iterable
And as the extend description from the manual hints, you can do the same thing with slices. You can also concatenate lists using '+'Lists are important in Python. You need to REALLY understand how they work or it is going to come back to bite you again and again.