Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.032 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'arguments': 0.09; 'constructor': 0.09; 'subject:question': 0.10; 'cc:addr:python- list': 0.11; '>>': 0.16; '>on': 0.16; '>the': 0.16; 'dict': 0.16; 'tuples,': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'of.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'yes.': 0.31; 'copying': 0.34; 'skip:d 20': 0.34; 'received:209.85': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'keyword': 0.36; 'skip:> 10': 0.36; 'list': 0.37; 'received:209': 0.37; 'being': 0.38; 'feed': 0.38; 'skip:& 20': 0.39; 'bad': 0.39; "you're": 0.61; 'skip:n 10': 0.64; 'dict()': 0.84; 'on?': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=22cQ5xWGuGqsTjdJQ3Ccq6Iyo/zeEwTpnpnUNDxuGyU=; b=c5z8og+eBrmqAOFmhBpSKrjExvFYUQwv9Eg+NZg5mccf8/foeaQ6My3Dij+2Ilhvee EswcVhO2oUl8kKH8TTr8Jrwk5cK5fij2umd6UeQx7v+1lW0m+v42Zi2YuMdcTG4/I8FS QDDfc0czG9+2i7zOV6eSPnvo1yJVYZ/Z1012Dsx+l3Y9bY9pLYXIcXP/k3ypF/aPCXRe aJL3Wf7d9ngxJ+TIUu3UNu/0tdq1WY6kx0+CDTjGHByedWenqtV+G/fXRS9bh39a8S4V z/MXtZGfDi0/lowkTKEVPAn5ivrvMKt0pJmVmmiC9ByvmJotC02Wsks5YnNZKpCHwfpP FcNw== MIME-Version: 1.0 X-Received: by 10.229.106.90 with SMTP id w26mr774421qco.138.1370348118800; Tue, 04 Jun 2013 05:15:18 -0700 (PDT) In-Reply-To: References: <323f2f5b-1f50-4689-90b8-74c411e43971@googlegroups.com> <1ba2ceec-f778-4c95-bf98-260fc48b4c3f@googlegroups.com> Date: Tue, 4 Jun 2013 13:15:18 +0100 Subject: RE: Beginner question From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Carlos Nepomuceno Content-Type: multipart/alternative; boundary=0023544714c4d7510404de530884 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370348127 news.xs4all.nl 15937 [2001:888:2000:d::a6]:44605 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46883 --0023544714c4d7510404de530884 Content-Type: text/plain; charset=ISO-8859-1 On 4 Jun 2013 12:57, "Carlos Nepomuceno" wrote: > > >On 4 Jun 2013 12:28, "Carlos Nepomuceno" wrote: > [...] > > >> What's going on? Is there a way to make dict() to resolve the variables? > >Well yes. > >dict(**{a:0,b:1}) > >The dict() constructor makes a dictionary from keyword arguments. So you just have to feed it keyword arguments using **. > >And if you're in a bad day, > >dict(**locals()) > > That's exactly the same! > >>>dict(**{a:0,b:1})=={a:0,b:1} > True > > Are there any benefits from using dict() instead of {}? Other than being able to create a dict from a list of tuples, and copying a dict using dict(anotherdict.items()), not that I know of. --0023544714c4d7510404de530884 Content-Type: text/html; charset=ISO-8859-1


On 4 Jun 2013 12:57, "Carlos Nepomuceno" <carlosnepomuceno@outlook.com> wrote:
>
> >On 4 Jun 2013 12:28, "Carlos Nepomuceno" <carlosnepomuceno@outlook.com> wrote:
> [...]
>
> >> What's going on? Is there a way to make dict() to resolve the variables?
> >Well yes.
> >dict(**{a:0,b:1})
> >The dict() constructor makes a dictionary from keyword arguments. So you just have to feed it keyword arguments using **.
> >And if you're in a bad day,
> >dict(**locals())
>
> That's exactly the same!
> >>>dict(**{a:0,b:1})=={a:0,b:1}
> True
>
> Are there any benefits from using dict() instead of {}?

Other than being able to create a dict from a list of tuples, and copying a dict using dict(anotherdict.items()), not that I know of.

--0023544714c4d7510404de530884--