DEV Community

loading...
Cover image for Python utility belt: unpacking tuples

Python utility belt: unpacking tuples

furtleo profile image Leonardo Furtado ・1 min read

Hi devs,
hi

Today I would like to show you something interesting that you can use. Take a look at this code:

things = [('teen', '10'), ('twenty', '20')]
Enter fullscreen mode Exit fullscreen mode

How do you print this? You've probably already thought of some ways to do this and now I'm going to show you some::

for index, (word, number) in enumerate(numbers):
    print(index, word, number)
Enter fullscreen mode Exit fullscreen mode

When you run this code, you'll receive it:

0 teen 10
1 twenty 20
Enter fullscreen mode Exit fullscreen mode

It is simple and useful, is it?
easy
Hope you enjoy it, have a great day and an AWESOME year.

Discussion (0)

pic
Editor guide