I know there is no frozen dict data type but If there was one how would it be different from namedtuple. It seems to me that namedtuple performs the required operations but obviously it does not. So what are the differences?
From an API viewpoint, probably not much, though:
namedtuple
keys are always strings with some limitations:Any valid Python identifier may be used for a fieldname except for names starting with an underscore. Valid identifiers consist of letters, digits, and underscores but do not start with a digit or underscore and cannot be a keyword such as class, for, return, global, pass, or raise.
namedtuple
s can always be accessed as regular tuples.Internally they are very different:
Named tuple instances do not have per-instance dictionaries, so they are lightweight and require no more memory than regular tuples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With