loading...

re: What is the simplest code to explain a loop? VIEW POST

FULL DISCUSSION
 

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
 

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

code of conduct - report abuse