Top "Namedtuple" questions

namedtuple is a data structure provided by the Python collections module.

Existence of mutable named tuple in Python?

Can anyone amend namedtuple or provide an alternative class so that it works for mutable objects? Primarily for readability, I …

python mutable namedtuple
Type hints in namedtuple

Consider following piece of code: from collections import namedtuple point = namedtuple("Point", ("x:int", "y:int")) The Code above is …

python python-3.x type-hinting namedtuple python-dataclasses
Pythonic way to sorting list of namedtuples by field name

I want to sort a list of named tuples without having to remember the index of the fieldname. My solution …

python sorting namedtuple field-names
how do I add fields to a namedtuple?

I am working with a list of namedtuples. I would like to add a field to each named tuple after …

python namedtuple
Looping over elements of named tuple in python

I have a named tuple which I assign values to like this: class test(object): self.CFTs = collections.namedtuple('CFTs', …

python namedtuple
How to access a field of a namedtuple using a variable for the field name?

I can access elements of a named tuple by name as follows(*): from collections import namedtuple Car = namedtuple('Car', 'color …

python namedtuple
How to pickle a namedtuple instance correctly

I'm learning how to use pickle. I've created a namedtuple object, appended it to a list, and tried to pickle …

python python-2.7 pickle namedtuple
Inheriting from a namedtuple base class

This question is asking the opposite of Inherit namedtuple from a base class in python , where the aim is to …

python oop inheritance super namedtuple
What is the pythonic way to read CSV file data as rows of namedtuples?

What is the best way to take a data file that contains a header row and read this row into …

python csv namedtuple