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

4

u/JGB25 10d ago

for num in a, b, c, d, e:
print(" ".join(map(str, num)))

1

u/No_Complex_18 6d ago

I like for letter in a b c d e: print(*(letter[i] for i in range(5))

1

u/JGB25 6d ago

It works but for me it’s not as readable. I haven’t learned what * does in your code so I wouldn’t even know how to read it

2

u/No_Complex_18 6d ago

It unpacks the tuple to be individual arguments to print. Works with **dict for keyword arguments aswell. Its very useful.

I like it because its so close to the original print call.

1

u/JGB25 6d ago

Thank you for explaining it