Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Why, when two ways of specifying the same list, does it take up a different amount of memory?
>>> a = [[i for i in range(0, 5)] for j in range(0, 2)]
>>> a
[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]
>>> sys.getsizeof(a)
96
>>> a = [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]
>>> a
[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]
>>> sys.getsizeof(a)
80
Answer the question
In order to leave comments, you need to log in
because they are different objects... in the first case it is a list generator, in the second it is a list
>>> a = [[i for i in range(0, 5)] for j in range(0, 2)]
>>> a
[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]
>>>
sys.getsizeof(a
) memory that is directly occupied by the generator itself ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question