Python add element to list in 4 ways

preview_player
Показать описание
Learn how to add an element to list in 4 different ways using append(), extend(), insert() functions of list and with concatenation(+) operator. Also, learn how to create a list of lists or tuples and add two lists together.
Рекомендации по теме
Комментарии
Автор

5th and faster way (by almost 50% vs append)... Pre-fill/allocate a list and then directly modify the index.

x[i] = value

This works if you can create one list, then utilize copies of that allocated list. Especially if working with hundreds of thousands of identically sized lists/arrays

anonymeister