3 ms·
No, what the docs say is that range is a generator. It never stores the entire list of values, but it does iterate through all the numbers, spitting them out on
by kilburn 8y ago
No, what the docs say is that range is a generator. It never stores the entire list of values, but it does iterate through all the numbers, spitting them out one by one (hence it uses O(1) memory, but O(n) computation).
Equivalent pseudocode:
function in_range(x, a, b):
for i=a; i<b; i++:
if x == i return true
return false