Tag: python
-
Can you explain this difference of depth recursion in Python using those seemingly equivalent codes?
6 I noticed that on my machine, the following reaches the max of depth recursion for n = 2960: m = {0:0, 1:1} def f(n): if n not in m: m[n] = f(n – 1) + f(n – 2) return m[n] while this version reaches it for n = 988: m = {0:0, 1:1} def…
-
Why is b.pop(0) over 200 times slower than del b[0] for bytearray?
24 Letting them compete three times (a million pops/dels each time): from timeit import timeit for _ in range(3): t1 = timeit(‘b.pop(0)’, ‘b = bytearray(1000000)’) t2 = timeit(‘del b[0]’, ‘b = bytearray(1000000)’) print(t1 / t2) Time ratios (Try it online!): 274.6037053753368 219.38099365582403 252.08691226683823 Why is pop that much slower at doing the same thing? python…