Python Built-in Methods: List, Tuple, Set, Dictionary
LIST METHODS (Ordered, Mutable, Allows Duplicates)
--------------------------------------------------
my_list = [1, 2, 3, 2]
my_list.append(4) # [1, 2, 3, 2, 4]
my_list.extend([5, 6]) # [1, 2, 3, 2, 4, 5, 6]
my_list.insert(1, 10) # [1, 10, 2, 3, 2, 4, 5, 6]
my_list.remove(2) # [1, 10, 3, 2, 4, 5, 6]
my_list.pop() # removes last element
my_list.index(3) # returns index of 3
my_list.count(2) # count of 2
my_list.sort() # sort ascending
my_list.reverse() # reverse order
my_list.copy() # shallow copy
TUPLE METHODS (Ordered, Immutable, Allows Duplicates)
------------------------------------------------------
my_tuple = (1, 2, 3, 2)
my_tuple.count(2) # 2
my_tuple.index(3) # 2
SET METHODS (Unordered, Mutable, Unique Elements)
-------------------------------------------------
my_set = {1, 2, 3}
my_set.add(4)
my_set.update([5, 6])
my_set.remove(2)
my_set.discard(10)
my_set.pop()
my_set.union({7, 8})
my_set.intersection({3, 4})
my_set.difference({3, 4})
my_set.symmetric_difference({3, 4})
my_set.issubset({1, 2, 3, 4})
my_set.issuperset({1, 2})
my_set.isdisjoint({7, 8})
DICTIONARY METHODS (Ordered, Mutable, Keys Unique)
--------------------------------------------------
my_dict = {"name": "Alice", "age": 25}
my_dict.get("name")
my_dict.keys()
my_dict.values()
my_dict.items()
my_dict.update({"city": "Delhi"})
my_dict.pop("age")
my_dict.setdefault("gender", "F")
dict.fromkeys(["a", "b"], 0)
my_dict.clear()