Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Why Slicing for Insert/Delete:** Demonstrates understanding of list immutability patterns. lst[:i] + [x] + lst[i:] creates new list—useful in functional style or when you need to preserve original. **Complexity:** O(n) for both—slicing copies. For frequent mid-list ops, list...
Why Slicing for Insert/Delete: Demonstrates understanding of list immutability patterns. lst[:i] + [x] + lst[i:] creates new list—useful in functional style or when you need to preserve original.
Complexity: O(n) for both—slicing copies. For frequent mid-list ops, list is wrong structure—use deque (ends) or linked structure (mid).
Production: In ETL, we rarely insert/delete by index—we filter (list comp) or use DataFrame drop/assign. This exercise is for interview fluency.
def insert_at(lst, i, x):
return lst[:i] + [x] + lst[i:]
def delete_at(lst, i):
return lst[:i] + lst[i+1:]
Red Flag: Claiming O(1) for list insert/delete. Pro-Move: 'For dynamic sequences we use blist or a custom ring buffer—list is for fixed-order data.'
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.