def l_system(depth, axiom, **rules):
    """Generate L-system from axiom using rules, up to given depth"""

    if not depth:
        return axiom
    
    # Basic, most straight-forward implementation
    # Note 1: it doesn't matter if axiom is a string or a list
    # Note 2: consider the difference between .extend() and .append()
    out = []
    for char in axiom:
        if char in rules:
            out.extend(rules[char])
        else:
            out.append(char)
    
    return l_system(depth - 1, out, **rules)