Inverse cascade challenge - Recursion Print the following pattern, when you invoke inverse_cascade(1234)

1
12
123
1234
123
12
1



Solution:

def inverse_cascade(n):
    def grow(n):
        if n &lt; 10:
            print(n)
        else:
            grow(n // 10)
            print(n)
    def shrink(n):
        if n &lt; 10:
            print(n)
        else:
            print(n)
            shrink(n // 10)
    grow(n // 10)
    print(n)
    shrink(n // 10)


Using a recursion approach, how can I improve this code without using higher order functions?

Note: No data models have to be used.
Separate grow and shrink functions are not necessary. Instead you can have a single function that prints, recurses and prints again the same value when the recursion returns.

For example like this:

def inverse_cascade(n, digits=1):
    n = str(n)
    print(n[:digits])
    if digits &lt; len(n):
        inverse_cascade(n, digits+1)
        print(n[:digits])