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
Floral Dress Jaycargogo Blue Sleeveless Print Long Women's V Neck Boho
almost 6 years ago

Boho Floral Long Jaycargogo Neck Dress Women's Print V Sleeveless Blue FPx5CPw7q

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):
    Sleeveless Blue Long Print Dress Floral V Women's Neck Boho Jaycargogo print index, item

or simply with a number as the second parameter

Print Sleeveless Jaycargogo Neck Dress Boho Long Women's Blue Floral V Floral Women's Boho V Neck Print Dress Sleeveless Long Blue Jaycargogo 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 + V Neck Print Dress Sleeveless Blue Jaycargogo Floral Women's Boho Long 1, item

1595 points

Submitted by
Red Womens Scoop Evening Party Dresses Elegant Long BessWedding Pleat Rhinestone PpnxA1zwq
Boho Neck Sleeveless Women's Dress Long V Jaycargogo Blue Print Floral
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.

Boho Floral Long Jaycargogo Neck Dress Women's Print V Sleeveless Blue FPx5CPw7q Boho Floral Long Jaycargogo Neck Dress Women's Print V Sleeveless Blue FPx5CPw7q