Adding an element to the end of a list
(list.append) works in O(1), but inserting in the middle of the list is O(n) because elements need to be shiftedIf you need to efficiently add elements from both ends, use
collections.deque — there operations on the edges have complexity O(1)https://t.me/DataScience4
