Complexity of len() with regard to sets and lists
Firstly, you have not measured the speed of len(), you have measured the speed of creating a list/set together with the speed of len(). Use the –setup argument of timeit: $ python -m timeit –setup “a=[1,2,3,4,5,6,7,8,9,10]” “len(a)” 10000000 loops, best of 3: 0.0369 usec per loop $ python -m timeit –setup “a={1,2,3,4,5,6,7,8,9,10}” “len(a)” 10000000 loops, … Read more