Python 3.2: How to pass a dictionary into str.format() Python 3.2: How to pass a dictionary into str.format() python-3.x python-3.x

Python 3.2: How to pass a dictionary into str.format()


This does the job:

stats = { 'copied': 5, 'skipped': 14 }print( 'Copied: {copied}, Skipped: {skipped}'.format( **stats ) )  #use ** to "unpack" a dictionary

For more info please refer to:


you want .format(**stats) as that makes stats part of format's kwargs.