Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 569 Bytes

20231212143456.md

File metadata and controls

27 lines (20 loc) · 569 Bytes

Sparse is better than dense.

Just by using more space (e.g. characters + newlines) your code will be much more pleasant / readable.

# dense
def generate_xmas_tree(rows=10):
    width, output = rows*2, []
    for i in range(1, width+1, 2):
        row = "*"*i
        output.append(row.center(width, " "))
    return "\n".join(output)


# sparse
def generate_xmas_tree(rows=10):
    width = rows * 2
    output = []

    for i in range(1, width + 1, 2):
        row = "*" * i
        output.append(row.center(width, " "))

    return "\n".join(output)

#zen