Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!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.95; '*S*': 0.01; 'mentioned,': 0.07; 'arguments': 0.09; 'constructor': 0.09; 'python:': 0.09; 'themselves,': 0.09; 'subject:question': 0.10; '>on': 0.16; '>the': 0.16; 'dict': 0.16; 'identifiers,': 0.16; 'nevertheless': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'thus': 0.29; 'easier': 0.31; 'keys': 0.31; 'steven': 0.31; 'yes.': 0.31; 'there': 0.35; 'keyword': 0.36; 'skip:> 10': 0.36; 'feed': 0.38; 'to:addr:python- list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'most': 0.60; "you're": 0.61; 'skip:n 10': 0.64; 'more': 0.64; 'dict()': 0.84; 'judges': 0.84; 'carlos': 0.91; 'on?': 0.91; 'convinced': 0.93; '2013': 0.98 Date: Tue, 04 Jun 2013 13:16:36 -0400 From: Mitya Sirenef User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Beginner question References: <323f2f5b-1f50-4689-90b8-74c411e43971@googlegroups.com>, , <1ba2ceec-f778-4c95-bf98-260fc48b4c3f@googlegroups.com>, , , , In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370366201 news.xs4all.nl 16004 [2001:888:2000:d::a6]:42571 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46943 On 06/04/2013 07:53 AM, 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 what Steven already mentioned, a big advantage is that it's easier to make a dict if you have a lot of keys that are valid identifiers, and it's more readable, to boot: dict(red=1, blue=2, orange=3, violet=4, crimson=5, ...) VS. {'red':1, 'blue':2, 'orange':3, 'violet':4, 'crimson':5, ...} -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ Although the most acute judges of the witches and even the witches themselves, were convinced of the guilt of witchery, the guilt nevertheless was non-existent. It is thus with all guilt. Friedrich Nietzsche