How to Concatenate Lists in Python? [Interactive Guide]

Published: 09 March 2020
on channel: Finxter
406
10

So you have two or more lists and you want to glue them together. This is called list concatenation. How can you do that?

These are six ways of concatenating lists:

List concatenation operator +
List append() method
List extend() method
Asterisk operator *
Itertools.chain()
List comprehension

If you’re busy, you may want to know the best answer immediately. Here it is:

To concatenate two lists l1, l2, use the l1.extend(l2) method which is the fastest and the most readable.

To concatenate more than two lists, use the unpacking (asterisk) operator [*l1, *l2, ..., *ln].

Read the full article at:
https://blog.finxter.com/concatenate-...

~~~
Become a better coder! Download the 5x Python Cheat Sheet Course (PDF). It’s free!
** Click: https://blog.finxter.com/subscribe/ **

🐍 Cheating in Python? Of course! 🐍
See you soon -- it’s fun! 🤓
~~~

Experts in their fields read more books! Become a Python expert: 📚
... [Book] Coffee Break Python -- https://blog.finxter.com/coffee-break...
... [Book] Coffee Break Python workbook -- https://blog.finxter.com/coffee-break...
... [Book] Coffee Break NumPy -- https://blog.finxter.com/coffee-break...
... [Book] Brain Games Python -- https://blog.finxter.com/python-brain...
... [Book] Python One-Liners -- https://www.amazon.com/gp/product/B07...

And become a Python master the fun way!
~~~

Start earning money by creating your own Python coding business (free webinar):
https://blog.finxter.com/webinar-free...


On this page of the site you can watch the video online How to Concatenate Lists in Python? [Interactive Guide] with a duration of hours minute second in good quality, which was uploaded by the user Finxter 09 March 2020, share the link with friends and acquaintances, this video has already been watched 406 times on youtube and it was liked by 10 viewers. Enjoy your viewing!