Memory consumption of a list and set in Python
问题 >>> from sys import getsizeof >>> a=[i for i in range(1000)] >>> b={i for i in range(1000)} >>> getsizeof(a) 9024 >>> getsizeof(b) 32992 My question is, why does a set consume so much more memory compared to a list? Lists are ordered, sets are not. Is it an internal structure of a set that consumes memory? Or does a list contain pointers and set does not? Or maybe sys.getsizeof is wrong here? I've seen questions about tuples, lists and dictionaries, but I could not find any comparison between