'colab keeps on crashing after using the 'GLOBAL' keyword

I copied this program from stackoverflow and added the global keyword to know the length of the list and it crashed because the ram is full.Why?If I removed the Global key word it works fine.I just wanted to know why it keeps on crashing

def permutation(s):
    if len(s) == 1:
        return [s]
    global per_list
    per_list = []
    for i in s:
        rm = [x for x in s if x != i]
        ff = permutation(rm)
        for j in ff:
            per_list.append([i] + j)
    return per_list

s = [3,4,5]
permutation(s)
print(len(per_list))


Solution 1:[1]

Declare it as empty list outside the function first and try again.

// like this 
per_list = []

def permutation(s):
    //body

s = [3,4,5]
permutation(s)
print(len(per_list))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akash Yeole