Why use namedtuple instead of a regular dictionary?
The main advantage of namedtuple
is that it takes up less space (memory) than an equivalent dictionary.
Therefore, for large datasets, named tuples are more efficient.
By running the code above, you'll notice that a namedtuple
has a size of 64 bytes, whereas a dictionary takes up much more — 240 bytes. That's almost 4 times more memory.
Page of .
Leave a comment
You must be logged in to leave a comment.
Log in or
sign up to join the discussion.
Comments (0)