Python Dicts vs NamedTuples

Cluster debates advantages of namedtuples, dataclasses, and classes over dictionaries in Python for lightweight, immutable data structures, focusing on syntax, performance, type safety, and use cases.

➡️ Stable 0.6x Programming Languages
3,581
Comments
19
Years Active
5
Top Authors
#6868
Topic ID

Activity Over Time

2008
18
2009
35
2010
55
2011
101
2012
103
2013
185
2014
213
2015
133
2016
249
2017
317
2018
238
2019
246
2020
243
2021
345
2022
249
2023
292
2024
253
2025
298
2026
8

Keywords

e.g JS python.org FTW kentsjohnson.com UserDict DictMixin MyDataclass a.y KeyValue dictionaries python key key value self nested named immutable classes value

Sample Comments

erokar Dec 7, 2016 View on HN

Besides immutability, what are the advantages of using namedtuples instead of dicts?

_ZeD_ May 8, 2015 View on HN

why not use namedtuples (or plain tuples) instead of dictionaries?

S4M Oct 31, 2015 View on HN

Named tuples are fine, but what do they have over using classes or dictionaries?

lucian1900 Nov 24, 2011 View on HN

Yuck. Sorry, but this is worse than dicts or namedtuples in every way.

tomrod Sep 1, 2017 View on HN

Dumb question from a non-developer: wouldn't using a dict object make more sense if someone wanted an unordered named tuple?

miohtama Nov 28, 2014 View on HN

It lacks the same syntatic sugar as Python dicts :(

pekk Oct 25, 2013 View on HN

What is the advantage of this over using dictionaries?

bpicolo Aug 1, 2015 View on HN

Switch to namedtuples for lightweight data structures. No regrets.

guidopallemans Dec 11, 2025 View on HN

When you are making str -> Any dictionaries it's quite likely you're better off with dataclasses or namedtuples anyway.

hbrn Jan 27, 2023 View on HN

Can you elaborate? What exactly is wrong with dicts?