←back to thread

191 points jwilk | 1 comments | | HN request time: 0.223s | source
Show context
sundarurfriend ◴[] No.46230418[source]
Can someone ELI5 the core difference between this and named tuples, for someone who is not deep into Python? ChatGPT's answer boiled down to: unordered (this) vs ordered (NTs), "arbitrary keys, decided at runtime" vs "fixed set of fields decided at definition time" (can't an NT's keys also be interpolated from runtime values?), and a different API (`.keys()`, `.items()`), etc (I'm just giving this as context btw, no idea if there's inaccuracies in these).

So could this also have been approached from the other side, as in making unordered NamedTuples with support for the Mapping API? The line between dictionaries and named tuples and structs (across various languages) has always seemed a bit blurry to me, so I'm trying to get a better picture of it all through this.

replies(5): >>46230459 #>>46230674 #>>46230747 #>>46230783 #>>46237202 #
minitech ◴[] No.46237202[source]
On top of generating types dynamically being slow and bad as quietbritishjim said, “str values that also happen to be valid identifiers” is a very limiting dict key requirement.
replies(1): >>46242548 #
1. quietbritishjim ◴[] No.46242548[source]
Great point, I can't believe I missed that.