I'm trying to create a function "generate_tree(L)", that takes a list of letters and returns a binary tree. Where each letter is a leaf. for example, with the list:
L = ['A', 'B', 'C']
the function should randomly return one of these trees:
['A',['B', 'C']] or [['A','B'], 'C']
Where the first example represent this tree:

Well it's not going too well - I had a solution but it also returned a lot of empty lists and it was a mess. This is my attempt so far:
from random import randint
def generate_tree(L):
n = len(L)
if not L: #base case yield empty
yield L
return
randomSplit = randint(1,n-1)
leftList = L[0:randomSplit]
rightList = L[randomSplit:]
List = ['A','B','C']
list(generate_tree(L))
My attempt with randomSplit is to divide the list into two lists in a random non-empty position:
['A','B','C'] --> leftList: ['A'], rightList: ['B','C']
I know I need to send leftList and rightList recursively, but I can't get it right. I would love your take on this issue