Convert namedtuple to dictionary

tripsvt at gmail.com tripsvt at gmail.com
Wed Sep 25 18:45:49 EDT 2013


Need suggestions. 

Say, I have a namedtuple like this:

{'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321)

I need to convert it to:

{'a': {'x':123, 'y': 321},'b': {'x':123, 'y': 321}}

Follow-up question --

Which would be easier to work with if I had to later extract/manipulate the 'x', 'y' values? The format (dicts) above or a list of values like this:

{'a': ['x':123, 'y': 321],'b': ['x':123, 'y': 321]}



More information about the Python-list mailing list