[Tutor] high score lists
Kent Johnson
kent37 at tds.net
Sat Apr 16 13:52:37 CEST 2005
Chris Smith wrote:
> high = [(1000,"Denise"), (945,"Denise"), (883,"Denise"),
> (823,"Grant"), (779,"Aaron"), (702,"Pete"),
> (555,"Tom"), (443,"Tom"), (442,"Robin"), (404,"Pete")]
>
> for score, who in high:
> col1 = str(score).rjust(10)
> col2 = who.rjust(20).replace(' ', '.') #replace spaces with dots
> print col1 + col2
> ###
> --the output--
> 1000..............Denise
> 945..............Denise
> 883..............Denise
> 823...............Grant
> 779...............Aaron
> 702................Pete
> 555.................Tom
> 443.................Tom
> 442...............Robin
> 404................Pete
> --end output--
Sweet. Note that in Python 2.4 you can write
col2 = who.rjust(20, '.')
instead of
col2 = who.rjust(20).replace(' ', '.') #replace spaces with dots
Kent
More information about the Tutor
mailing list