List Methods and Operations
Adding Methods
append(x)- Adds x to endextend(iterable)- Adds all elements from iterableinsert(i, x)- Inserts x at index i
Removing Methods
remove(x)- Removes first occurrence (ValueError if not found)pop()- Removes and returns last (or at index)clear()- Removes all elementsdel list[i]- Deletes element at index
Search Methods
index(x)- Returns index of first xcount(x)- Returns count of x
Sorting
sort()- Sorts in-place, returns Nonesorted(list)- Returns new sorted listreverse()- Reverses in-placereversed(list)- Returns iterator
Copying
list[:]orlist.copy()- Shallow copycopy.deepcopy(list)- Deep copy
Key Points
append()adds ONE element,extend()adds MULTIPLEsort()modifies list,sorted()creates new- Shallow copy shares nested objects
pop()returns removed element,remove()doesn’t