Skip to content

Instantly share code, notes, and snippets.

Created April 22, 2020 18:44
What would you like to do?

Python Namedtuple to Dict to JSON

I've patched this together from several different tutorials.

from collections import namedtuple
import json

dict_list = []

Employee = namedtuple('Employee', 'FirstName, LastName, ID')
names_list = [['Michael', 'Jordan', '224567'], ['Kyle', 'Hynes', '294007'], ['Josef', 'Jones', '391107']]
employee_list = map(Employee._make, names_list)

for e in employee_list:

y = json.dumps(dict_list)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment