Python DataStructures Methods
Python DataStructures Methods
1. List Methods
l = [1, 2, 3]
l.append(4) # [1, 2, 3, 4]
l.remove(99) # [1, 2, 3, 4, 5, 6]
l.index(4) #3
l.count(2) #1
l.reverse() # [5, 4, 3, 2, 1]
l.sort() # [1, 2, 3, 4, 5]
l.copy() # [1, 2, 3, 4, 5]
2. Tuple Methods
t = (1, 2, 3, 2, 4)
t.count(2) #2
t.index(3) #2
3. Set Methods
s = {1, 2, 3}
s.add(4) # {1, 2, 3, 4}
s.remove(3) # {1, 2, 4, 5, 6}
s.discard(10) # No error
s.intersection({4}) # {4}
s.difference({4}) # {2, 5, 6}
4. Dictionary Methods
d = {'name': 'Amit', 'age': 21}
d.get('name') # Amit
d.clear() # {}
len(l) #3
sum(l) # 60
max(l) # 30
min(l) # 10