I'm just wondering why I'm getting the error: RecursionError: maximum recursion depth exceeded When trying:
def permutations(string):
permlist = permutations(string)
combolist = []
for perm in list(permlist):
if ''.join(perm) not in combolist:
combolist.append(''.join(perm))
print(f"{combolist}")
I get this error:
permlist = permutations(string)
[Previous line repeated 996 more times]
RecursionError: maximum recursion depth exceeded
However, when I try it outside of a def, it works no problem:
permlist = permutations('abba')
combolist = []
for perm in list(permlist):
if ''.join(perm) not in combolist:
combolist.append(''.join(perm))
print(f"{combolist}")
output:
['abba', 'abab', 'aabb', 'baba', 'baab', 'bbaa']
I'm not very familiar with itertools or permutations or anything, but I'm just wondering why the permutation is recurring in a def, is there any way to possibly run the permutation once in the def, when executing the for loop afterwards or something?
Any help would be much appreciated!