Merge Python lists into one

Merging Python lists together is as easy as using the +.

orders = ['cheeseburger'] + ['soda']

print(orders)
# => ['cheeseburger', 'soda']

You can leverage the extend() function for this purpose as well. You call it on the list you want to extend and pass it a list.

orders.extend(['fries'])

print(orders)
# => ['cheeseburger', 'soda', 'fries']

Be aware that you pass it a list, not just a string. If you pass it just a string all the characters get inserted individually.

orders.extend('fries')

print(orders)
# => ['cheeseburger', 'soda', 'f', 'r', 'i', 'e', 's']

See Also

6 Non-Programming Books for Programmers