[Chicago] constant length string manipulation

Ed Leafe ed at leafe.com
Thu Nov 29 22:57:40 CET 2007


On Nov 29, 2007, at 4:45 PM, Ian Bicking wrote:

> def fivespaces(s):
>      while len(s) < 5:
>          s += ' '
>      while len(s) > 5:
>          s = s[:-1]
>      return s

	Why not just: return s.ljust(5)[:5]

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com




More information about the Chicago mailing list