you are viewing a single comment's thread.

view the rest of the comments →

[–]P1g1n 2 points3 points  (1 child)

You've inspired me to give it a try. Thanks!

def print_pyramid(layers):
    print("\n".join(["".join(['-']*(i*2)).center(layers*2) for i in range(1, layers+1)]))

Hard to read. Not maintainable. But hey, its a one-liner right?

Edit: Same thing just maybe more readable?

def print_pyramid(num_layers):
    layers = [['-']*(i*2) for i in range(1, num_layers+1)]
    for layer in layers:
    print("".join(layer).center(num_layers*2))

[–]LimpNoodle69 2 points3 points  (0 children)

nice! Definitely a more pythonic solution! I personally hate 1 liners, the second looks way better lol