Category Python List

Python List Length: How to Count Items with len()

Python List Length: How to Count Items with len()

len() on a list of ten million integers takes roughly 2.5 microseconds, while a Python loop over the same list takes roughly 300 milliseconds. The difference comes from a stored count rather than a faster algorithm, which decides the length…