2025-08-27
linear, hierarchical, graph, and unorderedstring, list, tuple, set, and dictionary
stacks, queues, priority queues, binary search trees, heaps, graphs, bags, and other various types of sorted collectionsLists[]to enclose items separated by commasListsappend, insert, pop, remove, and sort testList = [] # testList is []
testList.append(34) # testList is [34]
testList.append(22) # testList is [34, 22]
testList.sort() # testList is [22, 34]
testList.pop() # Returns 22; testList is [34]
testList.insert(0, 22) # testList is [22, 34]
testList.insert(1, 55) # testList is [22, 55, 34]
testList.pop(1) # Returns 55; testList is [22, 34]
testList.remove(22) # testList is [34]
testList.remove(55) # raises ValueErrorTupleDictionariesmutableSetsmy_set = {1, 2, 3}Examples include arrays, lists, stacks, and queues
Examples include binary trees, heaps, and general trees
Examples include undirected graphs, directed graphs, and weighted graphs
Examples include sets, dictionaries, and bags

in, +, len, str, and the for looppop is used to remove items at given positions from a Python list or values at given keys from a Python dictionaryremove is used to remove given items from a Python set or a Python liststring to a list and a list to a tupleis and == operators:list function makes a shallow copy of its argument listfor loop over the source collectionfor loop:
for loop serves up a collection’s items depends on the manner in which the collection is organizedfor loop plays a useful role in the implementation of several other basic collection operations, such as +, str, and type conversionsmap, filter, and reducelistsabstraction: