Append vs insert time in Python lists 🐍 #python #shorts

preview_player
Показать описание
Does it matter where you insert elements? For small lists, not really. But for large lists it makes a huge difference. Append is O(n) or constant time. This means it takes the same amount of time no matter how large the list. Insert (at the beginning of the list) is O(n) or linear time. The larger the list is, the longer it takes.
Рекомендации по теме