List and Set Methods
List and Set Methods
L1 = [1,2.5,’abcd’,1,2,3]
L2=[4,5,6,’xyz’]
append() Adds an element at the end of the list list.append(elmnt) L1.append(True)
clear() Removes all the elements from the list.clear() L1.clear()
list
copy() Returns a copy of the list list.copy() L3=L1.copy()
count() Returns the number of elements with list.count(value) L1.count(1)
the specified value
extend() Add the elements of a list (or any list.extend(iterable) L1.extend(L2)
iterable), to the end of the current list any iterable (list, set,
tuple, etc.)
index() Returns the index of the first element list.index(elmnt) print(L1.index(‘abcd’))
with the specified value
insert() Adds an element at the specified list.insert(pos, elmnt) L1.insert(2,True)
position
pop() Removes the element at the specified list.pop(pos) L1.pop(4)
position
remove() Removes the first item with the list.remove(elmnt) L1.remove(‘abcd’)
specified value
reverse() Reverses the order of the list list.reverse() L1.reverse()
sort() Sorts the list list.sort(reverse=True|Fa L1.sort()
lse, key=myFunc)
Set Methods