[Tutor] Address book sort of

R. Alan Monroe amonroe at columbus.rr.com
Mon Dec 6 12:44:27 CET 2004


>       spaceMult=(highLength+minimumSpaces)-len(key)
>       outString=str(index)+". "+key+(spaceMult * " ") + item
>       print outString

>             while len(display_name) < 25:
>                 display_name += '.'
>             count += 1
>             print count, display_name, d[item]

Rather than futzing with len()-based solutions, you might want to just
specify lengths in format strings:

>>> a='alan'
>>> print '*%10s*%-10s*' % (a,a)
*      alan*alan      *

Alan



More information about the Tutor mailing list