Possible Duplicate:
Merge two lists in python?
How can I prepend list elements into another list?
A = ['1', '2']
B = ['3', '4']
A.append(B)
print A
returns
['1', '2', ['3', '4']]
How can I make it
['1', '2', '3', '4']?
append() adds the new elements as another list, by appending the object to the end. To actually concatenate (add) lists together, and combine all items from one list to another, you need to use the . extend() method.
What are duplicates in a list? If an integer or string or any items in a list are repeated more than one time, they are duplicates.
ArrayList allows duplicate values while HashSet doesn't allow duplicates values.
A.extend(B)
or
A += B
This text added to let me post this answer.
list.extend
, for example, in your case, A.extend(B)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With