I'm trying to wrap my head around how recursion works, particularly how you can break it down into sub parts and work on that while maintaining that it all belongs to one overall part, if that makes any sense.
So for example: if I am given a list like [1,2,3,4,5] and I want to write a function that continuously creates a dictionary within a dictionary with each element in the list being the key; the output being like this - {1:{2:{3:{4:{5:{}}}}}}.
I know it can be done with a simple for loop but the point is I want to learn how recursion works. Here is what I tried and I know it's probably pretty far off. :(
data = [1,2,3,4,5]
split_order = dict()
def split(data, split_order):
if len(data) == 0:
return split_order
else:
attr = data[0]
new_data = data[1:]
split_order[attr] = dict()
split_order[attr] = split(new_data, split_order[attr])