[Chicago] April Talk Topic Python 3.2 Features

Brian Curtin brian at python.org
Tue Mar 13 04:59:33 CET 2012


On Fri, Mar 9, 2012 at 06:56, Brian Ray <brianhray at gmail.com> wrote:
> Question 1)  Why does {} have 0?
>
>
> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678}
> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; '
>            'Dcab: {0[Dcab]:d}'.format(table))
>
> Jack: 4098; Sjoerd: 4127; Dcab: 8637678

If you're just passing a single dict like this, you can unpack it and
access the values directly by key without worrying about an index.

print('Jack: {Jack:d}; Sjoerd: {Sjoerd:d}; Dcab: {Dcab:d}'.format(**table))


More information about the Chicago mailing list