mastering python chapter3
TRANSCRIPT
Advanced Collections• ChainMap
• Counter
• DefaultDic
• OrderedDic
• Deque
• Heapq
• Named Tuple
• Enum
List• A mutable list of items
• Time Complexity
• append, get, set, Len: O(1)
• remove, insert: O(n)
Dict• Unsorted but a fast map of items
• Time Complexity
• O(1) expected
• Worst Case: O(n) (hash Collision
• When deleting items from a dictionary, it won’t actually resize the dictionary in memory yet
Set• Like a dict without Values
• Time Complexity
• O(1) expected
• Worst Case: O(n) (hash Collision)
Tuple• The immutable list
• Hashable
• Possible to be used as a key in a dict
• A variable number of items (ex. *egg)
Counter• Keeping track of the most occurring elements
• Supporting operations similar to the set operations
Deque• The double ended queue
• Created as a doubly linked list, which means that every item points to the next and the previous item
• Adding and removing items from either the beginning or the end a very light O(1) operation
• Supporting operations similar to the set operations
Enum• A group of constants
• Making it really easy to have constants in your modules while still avoiding magic numbers
• Iterable
• Not just integers bug custom types as well
Heapq• The ordered list
• Heap: A binary tree for which every parent node has a value less than or equal to any of its children