How to Concatenate Lists in Python? [Interactive Guide]

Publicado em: 09 Março 2020
no canal de: 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...


Nesta página do site você pode assistir ao vídeo on-line How to Concatenate Lists in Python? [Interactive Guide] duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Finxter 09 Março 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 406 vezes e gostou 10 espectadores. Boa visualização!