List methods — append, insert, remove, pop, sort, reverse, count, index
WHY do these methods exist?
A list stores data in a sequence with positions called indices (starting at 0). Once you have data, you need to:
- Grow it →
append,insert - Shrink it →
remove,pop - Reorder it →
sort,reverse - Query it →
count,index
Without these you'd have to rebuild the whole list by hand every time — slow and error-prone. These methods do the bookkeeping for you.
WHAT each method does (the contract)
HOW it works under the hood (derive the behaviour)
A list is laid out as positions where len(lst).
append — derive its index. The end of a list of length is the next free slot: After appending, length becomes .
insert(i, x) — everything at position must move to to make room:
This is why insert near the front is "slow" (many shifts) while append is "fast" (no shifts).
pop(i) — returns lst[i], then everything at moves to to close the gap. Length becomes .

Worked examples
Recall Feynman: explain to a 12-year-old
Imagine a row of numbered lockers. append puts a bag in the next empty locker at the end. insert squeezes a bag into a chosen locker and pushes everyone after it down one. pop takes a bag out and hands it to you. remove finds a specific bag and throws it away (gives you nothing back). sort lines up all the bags from smallest to biggest, reverse flips the whole row. count tells you "how many red bags?" and index tells you "which locker is the first red bag in?" The hand-back-or-not difference is the whole trick: pop hands you something, the others don't.
Flashcards
What does list.append(x) return?
None — it mutates the list in place, adding x to the end.Difference between remove and pop?
remove(value) deletes first matching value and returns None; pop(index) removes by index and returns the item.What does pop() with no argument do?
What does sort() return, and how to get a new sorted list instead?
None (sorts in place); use sorted(lst) for a new list.Does reverse() sort the list?
What happens with lst.remove(x) if x is not present?
ValueError.What does count(x) return?
x appears in the list.What does index(x) return for a missing element?
ValueError; otherwise the index of the first occurrence.After [3,1,2].insert(1,9), what is the list?
[3, 9, 1, 2] — items at index ≥1 shift right.How to sort descending in one call?
lst.sort(reverse=True).Connections
- Lists — creation and indexing
- Mutability vs Immutability in Python
- sorted() vs list.sort()
- Tuples — why no append/sort
- Time complexity — append O(1) vs insert O(n)
- Strings — index and count methods
- Exceptions — ValueError and IndexError
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, ek Python list ko ek numbered shelf samjho jisme har dabbe ka ek index hota hai (0 se start). Ye aath methods us shelf ke saath kaam karne ke verbs hain. append end me item daalta hai, insert(i, x) kisi position pe ghusata hai aur baaki sab ko ek step right shift kar deta hai. remove(value) ek specific value ko dhoondh ke hata deta hai par kuch wapas nahi karta, jabki pop(index) item ko nikaal ke tumhe wapas de deta hai — yahi sabse important difference hai: pop "pays you back", remove "robs silently".
Sabse common galti: x = lst.sort() likhna. sort(), append, insert, remove, reverse ye sab list ko jagah-pe (in place) badalte hain aur None return karte hain. Isliye agar tum return value assign karoge to None mil jaayega aur lagega data gaayab ho gaya. Naya sorted list chahiye to function sorted(lst) use karo, method nahi.
count(x) batata hai kitni baar value aayi, aur index(x) pehli occurrence ka position deta hai — agar value nahi mili to ValueError aata hai, dhyan rakhna. Aur reverse() sort nahi karta, sirf order ulta karta hai; descending chahiye to lst.sort(reverse=True) best hai.
Yeh chhota sa group of methods 80/20 wala hai — interviews, DSA, aur daily coding sabme bar-bar aate hain. Ek baar add/take/move/ask categories yaad ho gayi, to kabhi confuse nahi hoge.