Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54849
| Date | 2013-09-26 14:38 -0400 |
|---|---|
| From | Ned Batchelder <ned@nedbatchelder.com> |
| Subject | Re: Convert namedtuple to dictionary |
| References | <6962B501-781B-4D05-93C6-50E3FFBAE9A4@maansystems.com> <52447223.2080908@nedbatchelder.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.367.1380221114.18130.python-list@python.org> (permalink) |
On 9/26/13 1:42 PM, Ned Batchelder wrote:
> On 9/26/13 1:17 PM, Virendra Tripathi wrote:
>> Hi Ned,
>>
>> Thanks. Wouldn't I have to first create a function to pull out the
>> 'dictdict' from the data? I assume 'dictdict' refers to the
>> 'brucelee' named tuple in the example. That's where I was getting
>> stuck-trying to pull out the named tuples from the dict and operate
>> on it.
> I assumed you already had the data you showed. This is tupledict:
>
> {'a': brucelee(x=123, y=321), 'b': brucelee('x'=123, 'y'=321)
>
> Given that, you create dictdict with the line I showed:
>
> dictdict = { k: nt._asdict() for k, nt in tupledict }
>
Oops:
dictdict = { k: nt._asdict() for k, nt in tupledict.iteritems() }
(sorry!)
--Ned.
>> Thanks,
>>
>> Virendra
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Convert namedtuple to dictionary Ned Batchelder <ned@nedbatchelder.com> - 2013-09-26 14:38 -0400
csiph-web