DEV Community

Cover image for Python Tips & Tricks Day 1

Python Tips & Tricks Day 1

ahmed elboshi on March 07, 2024

🎩✨ Python Party Trick vs. Stone Age Code! ✨🎩 Hey Python pals! 👋 Tired of coding like a caveman? 🦕 Let's upgrade that Stone Age script with a slick...
Collapse
 
msopacua profile image
msopacua

Yes, zip is great. But your original is only longer because it sets name and age as variables, either for readability, better debugging or unfamiliarity with format string capabilities.
One unfamiliar with zip would write the first one as:

names = ['Alice', 'Bob', 'Charlie']
ages = [30, 25, 35]

for i, name in enumerate(names):
    print(f'{name} is {ages[i]} years old')

Enter fullscreen mode Exit fullscreen mode

And then it's equally long.

Collapse
 
ahmed__elboshi profile image
ahmed elboshi

I admire your mindset; it's a fantastic approach! Essentially, what I'm aiming for is to create very simple code tailored for budding ninja coders. I provide small examples showcasing the usage of the built-in 'zip' function.