String formatting using dictionaries

Clodoaldo Pinto clodoaldo.pinto at gmail.com
Sat Apr 22 09:05:12 EDT 2006


I know how to format strings using a dictionary:

>>> d = {'list':[0, 1]}
>>> '%(list)s' % d
'[0, 1]'

Is it possible to reference an item in the list d['list']?:

>>> '%(list[0])s' % d
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
KeyError: 'list[0]'

Regards, Clodoaldo Pinto




More information about the Python-list mailing list