Top "Namedtuple" questions

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

What are "named tuples" in Python?

Reading the changes in Python 3.1, I found something... unexpected: The sys.version_info tuple is now a named tuple: I …

python tuples namedtuple
Named tuple and default values for optional keyword arguments

I'm trying to convert a longish hollow "data" class into a named tuple. My class currently looks like this: class …

python default-value namedtuple optional-arguments
Convert a namedtuple into a dictionary

I have a named tuple class in python class Town(collections.namedtuple('Town', [ 'name', 'population', 'coordinates', 'population', 'capital', 'state_bird'])): # ... …

python dictionary tuples namedtuple
Serializing a Python namedtuple to json

What is the recommended way of serializing a namedtuple to json with the field names retained? Serializing a namedtuple to …

python json namedtuple
Getting name of value from namedtuple

I have a module with collection: import collections named_tuple_sex = collections.namedtuple( 'FlightsResultsSorter', ['TotalPriceASC', 'TransfersASC', 'FlightTimeASC', 'DepartureTimeASC', 'DepartureTimeDESC', 'ArrivalTimeASC', …

python namedtuple
Can't set attribute for subclasses of namedtuple

It looks like this or this are somewhat related threads, but still haven't figured things out :) I'm trying to create …

python class python-3.x namedtuple
Pythonic way to convert a dictionary into namedtuple or another hashable dict-like?

I have a dictionary like: d = {'a': 1, 'b': 2, 'c': 3, 'd': 4} which I would like to convert to a namedtuple. My …

python dictionary namedtuple
namedtuple._replace() doesn't work as described in the documentation

I was having trouble implementing namedtuple._replace(), so I copied the code right off of the documentation: Point = namedtuple('Point', …

python namedtuple
Why does Python not support record type? (i.e. mutable namedtuple)

Why does Python not support a record type natively? It's a matter of having a mutable version of namedtuple. I …

python collections namedtuple
What does *tuple and **dict mean in Python?

As mentioned in PythonCookbook, * can be added before a tuple. What does * mean here? Chapter 1.18. Mapping Names to Sequence Elements: …

python python-3.x tuples namedtuple iterable-unpacking