Convert from tuple of tuples to nested tuples in Python
Question: Is there a simple way to convert

    
    
    t = ((1,), (1, 2), (1, 2, 3), (1, 2, 3, 4), (1, 2, 3, 4, 5))
    

to the following recursive structure, where each following tuple is appended
as an element of the prior tuple

    
    
    (1, (1, 2, (1, 2, 3, (1, 2, 3, 4, (1, 2, 3, 4, 5)))))
    

What is the limit to this nesting? Can I have a 1000 or 10000 such nested
tuples?

UPDATE: It seems `t` nesting is unlimited (tried with 10000 after setting
recursion limit to 100).

On Window 7, Python 3.5) the recursion limit is around 300 at first, but can
be lifted as ([reference](http://stackoverflow.com/questions/3323001/maximum-
recursion-depth)). This is not related to structure `t`, but may be related to
Python routine accessing nested levels of the resulting structure.

    
    
    sys.getrecursionlimit()   # display current recursion level
    sys.setrecursionlimit(10000)  # set recursion level to 1000
    


Answer: Using [`functools.reduce`](https://docs.python.org/3/library/functools.html):

    
    
    >>> from functools import reduce
    >>> t = ((1,), (1, 2), (1, 2, 3), (1, 2, 3, 4), (1, 2, 3, 4, 5))
    >>> reduce(lambda a, b: b + (a,), reversed(t), ())
    (1, (1, 2, (1, 2, 3, (1, 2, 3, 4, (1, 2, 3, 4, 5)))))
    

