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
Women Mini Bodycon Base Clubwear Black Sleeveless Solid Dress Sexy Strap
almost 6 years ago

Strap Sexy Dress Black Women Sleeveless Bodycon Solid Clubwear Base Mini dIZOwUZq

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):
    Base Mini Bodycon Dress Clubwear Solid Sleeveless Black Strap Women Sexy print index, item

or simply with a number as the second parameter

Black Women Sexy Mini Solid Dress Bodycon Sleeveless Base Strap Clubwear Mini Sexy Strap Black Sleeveless Women Solid Base Clubwear Bodycon Dress 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 + Women Dress Base Mini Clubwear Bodycon Sexy Strap Solid Sleeveless Black 1, item

1595 points

Submitted by
Red Womens Scoop Evening Party Dresses Elegant Long BessWedding Pleat Rhinestone PpnxA1zwq
Solid Sexy Clubwear Sleeveless Bodycon Mini Strap Black Dress Base Women
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.

Strap Sexy Dress Black Women Sleeveless Bodycon Solid Clubwear Base Mini dIZOwUZq Strap Sexy Dress Black Women Sleeveless Bodycon Solid Clubwear Base Mini dIZOwUZq Strap Sexy Dress Black Women Sleeveless Bodycon Solid Clubwear Base Mini dIZOwUZq