How to convert a namedtuple into a list of values and preserving the order of properties?

Question:

from collections import namedtuple
Gaga = namedtuple('Gaga', ['id', 'subject', 'recipient'])
g = Gaga(id=1, subject='hello', recipient='Janitor')

I want to be able to obtain this list (which preserves the order of the properties):

[1, 'hello', 'Janitor']

I could create this list myself manually but there must be an easier way.
I tried:

g._asdict().values()

but the properties are not in the order I want.

Asked By: canadadry

||

Answers:

Why not just list?

>>> list(g)
[1, 'hello', 'Janitor']
Answered By: Roman Bodnarchuk
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.