TIL - Big O notation; enum module
- Big-O doesn’t measure speed, it measures how performance degrades as n increases. It is about rate of decay.
- “Python is slow” is not always true, because a lot of Python operations do not stay in Python: they’re in optimized C.
- Python’s
inoperator is faster insetsthat inlists.Listsuse dynamic arrays. Python performs a linear search: it iterates through each element of the list until it finds a match or the end of the list. Time complexity:O(n).Setsuse hash tables which allow looking up key-value pairs quickly. Average-case time complexity:O(1), but in the worst caseO(n).
- The enum module is part of the standard library and allows creating enumerations (constant values grouped together under a common type). It allows for better readability and easier maintenance.
Privacy-First Subscription
Receive a notification in your inbox whenever I publish a new post. This is a reader-focused subscription loop built for absolute privacy: you stay in control, and I do not see, track, or collect your email address.
Follow via FeedRabbit