Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46943

Re: Beginner question

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 <msirenef@lightbird.net>
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 <msirenef@lightbird.net>
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 <CAA=1kxQFcMgSJ2_eD00B35V31WpbFiQ6LR=oBzrigg=8QoafCA@mail.gmail.com> <BLU176-W328C47391F61A540801441D79E0@phx.gbl>
In-Reply-To <BLU176-W328C47391F61A540801441D79E0@phx.gbl>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2667.1370366201.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 06/04/2013 07:53 AM, Carlos Nepomuceno 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 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Beginner question eschneider92@comcast.net - 2013-06-03 20:39 -0700
  RE: Beginner question Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 09:46 +0300
    Re: Beginner question John Ladasky <john_ladasky@sbcglobal.net> - 2013-06-04 00:53 -0700
      RE: Beginner question Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 11:17 +0300
  Re: Beginner question Anssi Saari <as@sci.fi> - 2013-06-04 10:45 +0300
    Re: Beginner question John Ladasky <john_ladasky@sbcglobal.net> - 2013-06-04 00:57 -0700
      Re: Beginner question Chris Angelico <rosuav@gmail.com> - 2013-06-04 18:24 +1000
      Re: Beginner question Peter Otten <__peter__@web.de> - 2013-06-04 11:23 +0200
      RE: Beginner question Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 14:23 +0300
        Re: Beginner question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-04 12:35 +0000
          RE: Beginner question Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 15:51 +0300
            Re: Beginner question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-07 02:21 +0000
      RE: Beginner question Fábio Santos <fabiosantosart@gmail.com> - 2013-06-04 12:34 +0100
      RE: Beginner question Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 14:53 +0300
        Re: Beginner question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-04 12:25 +0000
          RE: Beginner question Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-04 15:37 +0300
          RE: Beginner question Fábio Santos <fabiosantosart@gmail.com> - 2013-06-04 13:47 +0100
      RE: Beginner question Fábio Santos <fabiosantosart@gmail.com> - 2013-06-04 13:15 +0100
      Re: Beginner question Mitya Sirenef <msirenef@lightbird.net> - 2013-06-04 13:16 -0400
  Re: Beginner question Larry Hudson <orgnut@yahoo.com> - 2013-06-04 02:13 -0700
    Re: Beginner question Roy Smith <roy@panix.com> - 2013-06-04 09:16 -0400
  Re: Beginner question Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-04 20:43 +0100
  Re: Beginner question eschneider92@comcast.net - 2013-06-05 20:42 -0700

csiph-web