Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'assumed': 0.09; 'cc:addr :python-list': 0.11; 'assume': 0.14; "wouldn't": 0.14; 'dict': 0.16; 'subject:Convert': 0.16; 'tuple': 0.16; "{'a':": 0.16; 'sender:addr:gmail.com': 0.17; 'thanks,': 0.17; 'wrote:': 0.18; 'thanks.': 0.20; 'cc:addr:python.org': 0.22; 'header:User- Agent:1': 0.23; 'example.': 0.24; 'refers': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'getting': 0.31; 'tuples': 0.31; 'operate': 0.35; 'received:google.com': 0.35; 'pm,': 0.38; 'that,': 0.38; 'first': 0.61; 'batchelder': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=9kaK4Mjp5Xuq75JxdjAc9nPqJabGd1GQ86676LUcxCM=; b=MAfMPf5Bu3kMqEcdJGU/fiAN7ZfE7DkkLr41Edc7niba7UdPlcfh7fK+V1w68jvWRE Hc1GCNogaoaL2JzNMS6K+H6XPylFlNiAItxc5Y8pRmXjHnUe/jhwQZpVo6N0GOx8C72L Iz/KXCEdOyE8ZqbwnsPDP4uVJ9n+yyE6+FQsqg5esKvV9CgiZnGYp4r0p+AQwdBrIKgn y9NEApLEB//yFAVWAjalEmw8T8GZxounPpFh5XUKYxQGfLkaue+O04kIB5woTUC6AK7b 7qUiUqR3tL4kY+P7yYjOwIBbdioaOggEUQ2+5/NUxBy047gOoo1V50eMVYZW7tAzgebQ FrXg== X-Received: by 10.236.59.7 with SMTP id r7mr2003367yhc.42.1380220708018; Thu, 26 Sep 2013 11:38:28 -0700 (PDT) Sender: Ned Batchelder Date: Thu, 26 Sep 2013 14:38:26 -0400 From: Ned Batchelder User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: Virendra Tripathi Subject: Re: Convert namedtuple to dictionary References: <6962B501-781B-4D05-93C6-50E3FFBAE9A4@maansystems.com> <52447223.2080908@nedbatchelder.com> In-Reply-To: <52447223.2080908@nedbatchelder.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380221114 news.xs4all.nl 15909 [2001:888:2000:d::a6]:39868 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54849 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 >