Sitemap
Olivier Cruchant

Olivier Cruchant

Python, pandas, and actual wildlife - Views are mine and do not necessarily reflect those of my employer.

Python/named tuple magic

1 min readMay 4, 2018
import collectionscompany = collections.namedtuple('company', 'ceo, ticker, price')

Create instances from lists

Get Olivier Cruchant’s stories in your inbox

Join Medium for free to get updates from this writer.

# load some data from a list, e.g.:
data = [‘Jeff Bezos’, ‘AMZN’, 997]
# _make method
Amazon = company._make(data)
# or list unpacking; same result
Amazon = company(*data)

Get data back

Amazon.ticker

--

--

Olivier Cruchant
Olivier Cruchant

Written by Olivier Cruchant

Python, pandas, and actual wildlife - Views are mine and do not necessarily reflect those of my employer.