Complexity of len() with regard to sets and lists
问题 The complexity of len() with regards to sets and lists is equally O(1). How come it takes more time to process sets? ~$ python -m timeit "a=[1,2,3,4,5,6,7,8,9,10];len(a)" 10000000 loops, best of 3: 0.168 usec per loop ~$ python -m timeit "a={1,2,3,4,5,6,7,8,9,10};len(a)" 1000000 loops, best of 3: 0.375 usec per loop Is it related to the particular benchmark, as in, it takes more time to build sets than lists and the benchmark takes that into account as well? If the creation of a set object