Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46875
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <fabiosantosart@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'variables': 0.07; 'arguments': 0.09; 'constructor': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'answering...': 0.16; 'literals': 0.16; 'literals,': 0.16; 'ok!': 0.16; "{'a':": 0.16; 'wrote:': 0.18; 'variable': 0.18; 'resolved': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; '>': 0.26; 'switch': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'yes.': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'keyword': 0.36; 'feed': 0.38; 'bad': 0.39; 'providing': 0.61; "you're": 0.61; 'such': 0.63; 'skip:n 10': 0.64; 'as:': 0.81; '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=3ykr/T91XiN7yDm7oYVHAJ+avKdsOv7inZGsk/X/xbM=; b=YOpM8sR9omrbZtwiU67yqWhZp5kTn4XNiIT1DLF71LnFteZ6ygn7RXX43DXf7FD0id p29GLLQ3E2a+Oodurl7Q0WUCqWwFZ/XZkqRZGyTIBeAIQxi1n0Hl0ihV5RljEMMpXAqg 5khjimQ31WrWtVAb+LaNY/hZhuMhuRUOkhFq4c+X4pymzWhrr228Q71PmNg03zJucrPw t9dSD4i7SbNNaRQan7yj19vCdbWPs3MkQWQ8UxHh0m15fpMvbpxJQDVZWtmdeXfx4DCw bObNKNJzZl6p628ub6ek2iPNsUdGtXGsDzFrwUZLMnKO5zNRN/TkmbpzVVXZMFpU3mJG csdQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.49.62.72 with SMTP id w8mr26499454qer.22.1370345666559; Tue, 04 Jun 2013 04:34:26 -0700 (PDT) |
| In-Reply-To | <BLU176-W409F23043AF5028FCB3D50D79E0@phx.gbl> |
| References | <323f2f5b-1f50-4689-90b8-74c411e43971@googlegroups.com> <vg3hahefhel.fsf@coffee.modeemi.fi> <1ba2ceec-f778-4c95-bf98-260fc48b4c3f@googlegroups.com> <CAPTjJmrM=ai3g2XXSSULYvxdJKhvoTe61PefFC3tc20i5ajhHA@mail.gmail.com> <kokblm$eb0$1@ger.gmane.org> <BLU176-W409F23043AF5028FCB3D50D79E0@phx.gbl> |
| Date | Tue, 4 Jun 2013 12:34:26 +0100 |
| Subject | RE: Beginner question |
| From | Fábio Santos <fabiosantosart@gmail.com> |
| To | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
| Content-Type | multipart/alternative; boundary=047d7bdc0944acc68104de527618 |
| 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 <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.2636.1370345675.3114.python-list@python.org> (permalink) |
| Lines | 68 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370345675 news.xs4all.nl 15897 [2001:888:2000:d::a6]:37333 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:46875 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
On 4 Jun 2013 12:28, "Carlos Nepomuceno" <carlosnepomuceno@outlook.com>
wrote:
>
> Started answering... now I'm asking! lol
>
> I've tried to use dict() to create a dictionary to use like the switch
statement providing variable names instead of literals, such as:
>
> >>> a='A'
> >>> b='B'
> >>> {a:0,b:1} #here the variables are resolved
> {'A': 0, 'B': 1}
>
> That's ok! But if I use dict() declaration:
>
> >>> dict(a=0,b=1)
> {'a': 0, 'b': 1} #here variable names are taken as literals
>
> 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())
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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