I thinking of optimizing my code by leaving out some recursive calls and replacing them by while or other iterative loops.
Recursive function is this:
def repr(e):
if isinstance(e, (list, tuple)):
return "(%s)" % " ".join(map(repr, e))
return str(e)
Output for repr([1, [2, [3, 4]]]) is (1 (2 (3 4)))
Is there a way to replace map-part with while loop in this case? I'd like to test the performance difference between different ways of doing it.