Convert list to namedtuple

You can do Row(*A) which uses argument unpacking.

>>> from collections import namedtuple
>>> Row = namedtuple('Row', ['first', 'second', 'third'])
>>> A = ['1', '2', '3']
>>> Row(*A)
Row(first="1", second='2', third='3')

Note that if your linter doesn’t complain too much about using methods which start with an underscore, namedtuple provides a _make classmethod alternate constructor.

>>> Row._make([1, 2, 3])

Don’t let the underscore prefix fool you — this is part of the documented API for this class and can be relied upon to be there in all python implementations, etc…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)