[Tutor] rounding up to the nearest multiple of 8

Asokan Pichai pasokan at talentsprint.com
Fri Oct 5 11:06:10 CEST 2012


If you are doing so many times, it may be worth precomputing the padding for a
given length and adding it by a look up on the length.

For example:
------------------------
SPACE = ' '
MAX = 1000
TAB = 8
paddding = [ SPACE * (n % TAB) for n in range(MAX) ]

.....
s = padding[len(s)] + s
.....
--------------------------
where s is string to be padded

Asokan Pichai

If a language is designed for non-programmers, soon only
non-programs get written in it.                    --- Anonymouse


More information about the Tutor mailing list