What is the best way to convert list of lists/tuples to string with incremental indents.
So far I've ended up with such a function
def a2s(a, inc = 0):
inc += 1
sep = ' ' * inc
if type(a) == type(list()) or type(a) == type(tuple()):
a = sep.join(map(a2s, a))
else:
a = str(a)
return a
It would give
>>> a=[[1, 2], [3, 4]]
>>> a2s(a)
'1 2 3 4'
So the question is how to make increment between [1,2]
and [3,4]
larger, like this
>>> a2s(a)
'1 2 3 4'
If there any way to pass non-iterable 'inc' argument through the map function? Or any other way to do that?