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.

Comments (0)

Leave a comment