What is the easiest way to create a string of spaces of length N in Python?
(besides something similar, which is multi-line and supposedly inefficient for large n:
def spaces(n): s = '' for i in range(n): s += ' ' return s
)
try this, just one line only:
' ' * n
It's simple:
s = ' ' * N
You can do this as a function:
def spaces(n): return ' ' * n
Or just use the expression:
Above my head:
spaces = lambda x: ' ' * x
All these scammers are not funny, and their simple answers stink.
The true answer is:
def give_me_spaces(n): return (lambda : ''.join(' ' for _ in xrange(n)))()
Also, it is clearly superior because it uses functional programming.
Had to dig through my python helper functions to find this, but here it is. It served me well.
spaces = (lambda n: (lambda z: z(lambda f: lambda m:'' if m <= 0 else ' ' + f(m - 1))(n)) (lambda f:(lambda x:f(lambda*a:x(x)(*a)))(lambda x:f(lambda*a:x(x)(*a)))))