Problem Statement
When should you replace Python loops with vectorized operations or built-ins?
Explanation
Replace loops when you are doing simple numeric or array transformations that map well to C level operations. Libraries such as NumPy run inner loops in optimized C, often giving big speedups.
Even without NumPy, prefer built-ins like sum, min, max, any, all, and list comprehensions over manual loops. They are faster, clearer, and implemented in C where possible.
Code Solution
SolutionRead Only
nums=list(range(1_000_000)) # better total=sum(nums) # with numpy # import numpy as np; total=np.sum(np.array(nums))
