[Tutor] Dictionaries

Alan Gauld alan.gauld at freenet.co.uk
Fri Jan 27 18:50:30 CET 2006

> ...  print '%*s --> %*s' % (maxKey, name, maxValue, pairs[name])
> thanks for pointing out the '*' syntax. Ignorant as I am I have 
> had to write things like
>   print '%%%ss --> %%%ss' % (maxKey, maxValue) % (name, pairs[name])

I didn't even try that, I've always done it on two lines

fmt = "%%%ds --> %%%ds' % (width1,width2)
print fmt % (value1,value2)

'%*s' is a neat trick, albeit a tad obscure in the readability stakes.
But is %%%ds any better?!

Alan G.

More information about the Tutor mailing list