Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.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.063 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.02; 'arguments': 0.09; 'constructor': 0.09; 'subject:question': 0.10; '>>': 0.16; '>on': 0.16; '>the': 0.16; 'received:65.55.116.7': 0.16; 'wrote:': 0.18; 'to:name:python-list@python.org': 0.22; 'received:65.55.116': 0.24; 'header:In-Reply-To:1': 0.27; 'yes.': 0.31; 'there': 0.35; 'keyword': 0.36; 'skip:> 10': 0.36; 'feed': 0.38; 'to:addr:python-list': 0.38; 'skip:& 20': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; "you're": 0.61; 'dict()': 0.84; 'on?': 0.91; '2013': 0.98 X-TMN: [I/aSjVCBsG9MiYn6ujA1aI5+9yUc4cOf] X-Originating-Email: [carlosnepomuceno@outlook.com] Content-Type: multipart/alternative; boundary="_959f0729-fff1-49af-96e4-62ec96e7f5d0_" From: Carlos Nepomuceno To: "python-list@python.org" Subject: RE: Beginner question Date: Tue, 4 Jun 2013 14:53:29 +0300 Importance: Normal In-Reply-To: References: <323f2f5b-1f50-4689-90b8-74c411e43971@googlegroups.com>, , <1ba2ceec-f778-4c95-bf98-260fc48b4c3f@googlegroups.com>, , , , MIME-Version: 1.0 X-OriginalArrivalTime: 04 Jun 2013 11:53:29.0945 (UTC) FILETIME=[2180B490:01CE611A] 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: 1370346812 news.xs4all.nl 16004 [2001:888:2000:d::a6]:52693 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46880 --_959f0729-fff1-49af-96e4-62ec96e7f5d0_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable >On 4 Jun 2013 12:28=2C "Carlos Nepomuceno" = wrote: [...] >> What's going on? Is there a way to make dict() to resolve the variables? >Well yes. >dict(**{a:0=2Cb:1}) >The dict() constructor makes a dictionary from keyword arguments. So you j= ust have to feed it keyword arguments using **. >And if you're in a bad day=2C >dict(**locals()) That's exactly the same! >>>dict(**{a:0=2Cb:1})=3D=3D{a:0=2Cb:1} True Are there any benefits from using dict() instead of {}? = --_959f0729-fff1-49af-96e4-62ec96e7f5d0_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
>=3BOn 4 Jun 2013 12:28=2C "Ca= rlos Nepomuceno" <=3Bcarlosnepomuceno@outlook.com>=3B wrote:
[...]>=3B>=3B What's going on? Is there a way to make dict() to resolve th= e variables?
>=3BWell yes.
>=3Bdict(**{a:0=2Cb:1})
>=3BThe d= ict() constructor makes a dictionary from keyword arguments. So you just ha= ve to feed it keyword arguments using **.
>=3BAnd if you're in a bad d= ay=2C
>=3Bdict(**locals())

That's exactly the same!
>=3B&g= t=3B>=3Bdict(**{a:0=2Cb:1})=3D=3D{a:0=2Cb:1}
True

Are there any= benefits from using dict() instead of {}?
= --_959f0729-fff1-49af-96e4-62ec96e7f5d0_--