Making Code Faster
The most valuable optimization in everyday programming is replacing a nested search with a dictionary lookup. Checking whether something is in a list is O(n), because it may have to check every item. Checking a dictionary or set is O(1), because it jumps straight there.
✦ When not to optimize
Correct and readable beats fast and clever, until the data gets big enough to matter. Write the clear version first, measure whether it is actually too slow, and only then reach for a faster structure. Optimizing code nobody is waiting on is wasted effort, and the complicated version is where bugs live.
Mark this lesson complete
Signed in, your progress follows you to every device.