I notice that when using sys.getsizeof() to check the size of list and dictionary, something interesting happens.
i have:
a = [1,2,3,4,5]
with the size of 56 bytes (and empty list has size of 36, so it makes sense because 20/5 = 4)
however, after I remove all the items in the list (using .remove or del), the size is still 56. This is strange to me. Shouldn't the size be back to 36?
Any explanation?
The list doesn't promise to release memory when you remove elements. Lists are over-allocated, which is how they can have amortized O(1) performance for appending elements.
Details of the time performance of the data structures: http://wiki.python.org/moin/TimeComplexity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With