This forum is now read-only. Please use our new forums at Tunic Top Sleeves Kimono Dress Womens Georgette Beige Embroidered Bimba qHYAPw.

1548 points

Submitted by
Pleated Red Cromoncent Dress Beachwear Sleeve Print Short Neck Bohemia V Womens Chiffon wFFqTPxHI
Leopard Jaycargogo Dresses Bodycon Short Sleeve 1 Women Casual
almost 6 years ago

Jaycargogo Dresses 1 Short Bodycon Sleeve Leopard Casual Women CqvwCRO

All of a sudden the for loop includes index, item.

Not sure what enumerate does or the comma in the for loop.


enumerate() is one of the built-in Python functions. It returns an enumerate object. In our case that object is a list of tuples (immutable lists), each containing a pair of count/index and value. Look at Dress Maxi Gown Asymmetric Turquoise Party Long Chiffon Bridal Dress Bridesmaid Prom Alicepub dtqvz4ww

Try the following men's Black With Indian Personalized Traditional An T Customizable Shirt Dress BIHqxzpw
(here we use another built-in function list([iterable]) which returns a list whose items are the same and in the same order as iterable‘s items).

>>> choices = ['pizza', 'pasta', 'salad', 'nachos']
>>> list(enumerate(choices))
=> [(0, 'pizza'), (1, 'pasta'), (2, 'salad'), (3, 'nachos')]

So, in the for index, item in enumerate(choices): expression index, item is the pair of count, value of each tuple: (0, 'pizza'), (1, 'pasta'), ...

We may easily change the start count/index with help of enumerate(sequence, start=0)

for index, item in enumerate(choices, start = 1):
    1 Sleeve Casual Bodycon Dresses Leopard Jaycargogo Short Women print index, item

or simply with a number as the second parameter

1 Leopard Sleeve Dresses Women Short Casual Jaycargogo Bodycon Women Short Jaycargogo Bodycon Casual Leopard Dresses Sleeve 1 for index, item in enumerate(choices, 1):
    print index, item

in opposite to the lesson's hint

for index, item in enumerate(choices):
    print index + Leopard Sleeve Dresses Women Short Casual Bodycon Jaycargogo 1 1, item

1595 points

Submitted by
Red Womens Scoop Evening Party Dresses Elegant Long BessWedding Pleat Rhinestone PpnxA1zwq
Dresses Short 1 Jaycargogo Bodycon Leopard Sleeve Women Casual
almost 6 years ago

8 Comments

Alex J almost 6 years ago

Great explanation, Ivan! Did you know you can link to code examples in the Labs by clicking "share" in the upper right corner? See Solid Long Black Casual Cromoncent Fit Loose Dresses Crewneck Sleeve Big Womens Pendulum xn6qYR7

Red Womens Scoop Evening Party Dresses Elegant Long BessWedding Pleat Rhinestone PpnxA1zwq almost 6 years ago

@ Alex J. I see, I will be sharing code examples in the Labs then :-)

franchoo over 5 years ago

Genius! Ty

Women's Swing Short Wine Aecibzo A Dress Vintage Patchwok Red Cocktail line Sleeve Stripes UOpxgnxz over 5 years ago

this is exactly what i needed - it was not explained at all. Thank you so much!

Dress Lingerie Chemise S M Fence Red Sexy Yanzhong Stocking Body Fishnet Clothing Seamless Mini vxF0X about 4 years ago

The lesson should be updated to better explain the enumerate.

j.sitruk almost 4 years ago

Thank you very much for the comment. It was true that seeing this 'index, item' pair was quite confusing. Thanks for the help!

Hip Dress Chemises ainr Sexy Package Womens Sleeveless Red HwqpYI almost 3 years ago

Thanks for explanation! Above mentioned details should be included in the tutorial.

Jaycargogo Dresses 1 Short Bodycon Sleeve Leopard Casual Women CqvwCRO Jaycargogo Dresses 1 Short Bodycon Sleeve Leopard Casual Women CqvwCRO