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: 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; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'dict': 0.16; 'lot!': 0.16; "{'a':": 0.16; '>>>': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message- id:@mail.gmail.com': 0.30; 'skip:d 20': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36 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=VEQ4adFaK9/sGTnpYNmqxzUb2nI9mWcG+dcHhN4GjZs=; b=f3pMleA1+rJAHHqZaKkRONnBcPT2uxD7DRNf1krsSEyTbrls/moPiqnEMF2VPe/i+H ktZp8fkkB8lOnzKL+I1AgShl4Ko5+z2OBcdvWRR84EtRjdKuHx2uX7ga6so9rdSx4FfN D1rRLqT/QkIFSdpC3IyBDoog90ruXxeBSBxc7NPCpi+iCLPm2ELOfrZ0SLad6tJQPOYg eAa31R5LkkMSFKV7tbEQl4hC7I5HCGRBp+oRZ7Y56kvW/vLp4MTriLIqqnIxAi8nDLhG +xpTtiZs8CRnDYKtkzTB3GoGLEgBWP33ia7kJhxHsCaLC1Pzgy5YCkQltVvwLqj5wfkk yi9w== MIME-Version: 1.0 X-Received: by 10.224.174.6 with SMTP id r6mr23092787qaz.87.1370350064287; Tue, 04 Jun 2013 05:47:44 -0700 (PDT) In-Reply-To: References: <323f2f5b-1f50-4689-90b8-74c411e43971@googlegroups.com> <1ba2ceec-f778-4c95-bf98-260fc48b4c3f@googlegroups.com> <51addcb7$0$29966$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 4 Jun 2013 13:47:44 +0100 Subject: RE: Beginner question From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Carlos Nepomuceno Content-Type: multipart/alternative; boundary=485b397dd205ccc4a904de537c0f 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370350067 news.xs4all.nl 16011 [2001:888:2000:d::a6]:32818 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46889 --485b397dd205ccc4a904de537c0f Content-Type: text/plain; charset=ISO-8859-1 > > Awesome! Now I can do it just like that: > > >>> dict([(chr(ord('a')+x),x) for x in range(2)]) > {'a': 0, 'b': 1} > > Thanks a lot! ;) > Or dict((c, i) for (i, c) in enumerate('ab')) But at this point you could just use a dict comprehension. {c: i for i, c in enumerate('ab')} --485b397dd205ccc4a904de537c0f Content-Type: text/html; charset=ISO-8859-1


>
> Awesome! Now I can do it just like that:
>
> >>> dict([(chr(ord('a')+x),x) for x in range(2)])
> {'a': 0, 'b': 1}
>
> Thanks a lot! ;)
>

Or
dict((c, i) for (i, c) in enumerate('ab'))

But at this point you could just use a dict comprehension.

{c: i for i, c in enumerate('ab')}

--485b397dd205ccc4a904de537c0f--