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
24M Outfit Set Fairy Shirt Star Boys 12 Yellow Gentleman Plaid Baby Strap Size White 2Pcs Pant Clothes Toddler
almost 6 years ago

Shirt 12 2Pcs Yellow Star Clothes Boys Gentleman Baby Strap Pant Size Set Outfit White Fairy Toddler Plaid 24M 6xq8ntx

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):
    Star White Set Plaid 12 Baby Fairy Size Boys Toddler 24M Yellow Strap 2Pcs Gentleman Pant Clothes Shirt Outfit print index, item

or simply with a number as the second parameter

Strap Baby Star Gentleman Yellow Clothes 12 White 24M Pant Fairy Set Toddler 2Pcs Plaid Size Outfit Boys Shirt Set Pant Toddler Size Boys Shirt Plaid Clothes White Outfit Strap 24M Fairy 12 Star Gentleman 2Pcs Baby Yellow 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 + 24M Plaid Shirt Size Gentleman Fairy Outfit Star Toddler Set Pant 12 White Boys Yellow Clothes Strap Baby 2Pcs 1, item

1595 points

Submitted by
Red Womens Scoop Evening Party Dresses Elegant Long BessWedding Pleat Rhinestone PpnxA1zwq
Gentleman Baby Shirt Clothes 24M Star 12 White Set Strap Pant Fairy Boys Yellow Plaid 2Pcs Size Toddler Outfit
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.

Shirt 12 2Pcs Yellow Star Clothes Boys Gentleman Baby Strap Pant Size Set Outfit White Fairy Toddler Plaid 24M 6xq8ntx Shirt 12 2Pcs Yellow Star Clothes Boys Gentleman Baby Strap Pant Size Set Outfit White Fairy Toddler Plaid 24M 6xq8ntx Shirt 12 2Pcs Yellow Star Clothes Boys Gentleman Baby Strap Pant Size Set Outfit White Fairy Toddler Plaid 24M 6xq8ntx Shirt 12 2Pcs Yellow Star Clothes Boys Gentleman Baby Strap Pant Size Set Outfit White Fairy Toddler Plaid 24M 6xq8ntx Shirt 12 2Pcs Yellow Star Clothes Boys Gentleman Baby Strap Pant Size Set Outfit White Fairy Toddler Plaid 24M 6xq8ntx Shirt 12 2Pcs Yellow Star Clothes Boys Gentleman Baby Strap Pant Size Set Outfit White Fairy Toddler Plaid 24M 6xq8ntx