Beginner question

Fábio Santos fabiosantosart at gmail.com
Tue Jun 4 08:47:44 EDT 2013


>
> 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')}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130604/832550c7/attachment.html>


More information about the Python-list mailing list