DEV Community

Discussion on: What is the simplest code to explain a loop?

Collapse
 
alexmacniven profile image
Alex Macniven

At absolute beginner level, I wish I knew about enumeration (Python)

# in
my_list = ['apple', 'orange']
for index, item in enumerate(my_list):
    print(index, item)

# out
0 apple
1 orange
Collapse
 
karloabapo profile image
Karlo Abapo

enumerate and list comprehensions are the stuff after you get past the basic looping and collections. :)