Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Lists vs tuple in Python

I create my first python student project. I need save data about orders in online shop in books python. But I can’t understandwhat will be better: save informations in list with tuple (last mean in data must be changeable) or I can make just list. I see, that list with tuple take memorys less then list and tuple(!!!). But I was shoked, when I saw that all three methods – tuples, list and list with tuple, take memorys identically.
Quastion: 1. why list with tuple take memorys less, then just tuple? 2. why with all three methods dictionaries weigh the same? Thank you!enter image description hereenter image description here

I just checked memory usage by elements

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The issue is that "getsizeof" is not "recursive" in any meaningful way. When you create a list of tuple and a string, it is actually a list with a reference and a string. So the actual size of this first argument does not matter

([1,2],3).__sizeof__() == ([1,2,3,4,5,6,7],3).__sizeof__()

Same with dictionaries, you are getting size of the structure of key->reference, not key->dereferenced object

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading