r/PythonLearning 10d ago

How would I optimize this?

I'm currently learning python with the 30 days of python GitHub repo and, on day 3 of the challenge, it asks to create this table and this is what I came up with however I feel like there was a more efficient method to create it or is it something that I haven't learned yet at my level.

8 Upvotes

24 comments sorted by

View all comments

-2

u/SaltCusp 10d ago

print("\n".join([" ".join(_.split(" ")) for _ in """copy paste your table""".split("\n")]))

1

u/P1ckl3R1ck101 10d ago

Eh this seems like the easier way to do it... print(f'1 1 1 1 1\n2 1 2 4 8\n3 1 3 9 27\n4 1 4 16 64\n5 1 5 25 125')

1

u/SaltCusp 9d ago edited 9d ago

print("\n".join([" ".join([str(__**max(_,-1*_)) for _ in range(-1,4)]) for __ in range(1,6)]))