Notice how when someone asks something like that, some bizarro practitioners of such methods would always appear and say how they are invaluable for them...
Notice how when someone asks something like that, some bizarro practitioners of such methods would always appear and say how they are invaluable for them...
But I was referring to the parent's general observation that about "catering to some obscure use case that nobody uses", which I agree with -- not about their specific example.
"In mathematics a tuple is a finite ordered list (sequence) of elements. An n-tuple is a sequence (or ordered list) of n elements, where n is a non-negative integer. There is only one 0-tuple, an empty sequence. An n-tuple is defined inductively using the construction of an ordered pair." (Wikipedia)
Should order be important for a Tuple under a system that defines a Tuple as an immutable ordering?
That is, whatever your philosophical issues with namedtuple ordering, in python, a tuple is an immutable ordered list of things. In practice, tuples have taken the role of being type-heterogenous, known length, records.
One might then reasonably expect a namedtuple to be a type-heterogneous, known length, record, where attributes are named.
Or consider (firstname="John", lastname="Doe") vs (lastname="Doe", firstname="John").
I think you'd agree that they're the same.
Without ordering, you wouldn't be able to sanely run `sorted` on a iterable of namedtuples.
Namedtuples are for the convenience of creating a record type (though indeed as others say, treating it as tuple where things expect a tuple is also a benefit).
Don't call it an unordered namedtuple. That's confusing, because tuples are ordered.
A relation is defined as a set of n-tuples. In both mathematics and the
relational database model, a set is an unordered collection of unique, non-
duplicated items, although some DBMSs impose an order to their data. In
mathematics, a tuple has an order, and allows for duplication. E. F. Codd
originally defined tuples using this mathematical definition.
Later, it was one of E. F. Codd's great insights that using attribute names
instead of an ordering would be so much more convenient (in general) in a
computer language based on relations. This insight is still being used today.
Though the concept has changed, the name "tuple" has not."inessential" might be a better than "unimportant"
You have used some of these methods before. So are you bizzaro?
No. Nobody is bizarro for mentioning this, it's extremely handy and it's kind of in the name: namedtuple. Without this they are utterly pointless.
Although I can't tell if the moral of this is "if the api allows, it will be done, and you can't break the api later", or if the moral is "just because you think it's useless doesn't mean it really is".
That would be the bizarro practitioners who expect subclassing to actually be subclassing. Maybe there is a sane argument that namedtuple shouldn't be a subclass of tuple but that ship sailed a long time ago.
https://www.extremetech.com/computing/252987-python-tops-lis...
Not because you can monkeypatch the _attrs_ function on the fly somewhere on a class in the standard library.