Newbie

For a long time, I've been using this Python idiom when I needed both the list indices and the list elements:

for index in range(len(L)):
    print index, L[index]

Only today, I realized there's a much more elegant way to do the same:

for index, element in enumerate(L):
    print index, element

Gosh, I feel like such a newbie even after more than two years of using Python now!

Comments

Hear, hear. I've technically known C++ for ten years, and actively used it for five. Even though it's a far smaller base language, I still struggle every day with the stuff. Latest head-spinning concept - template specialization.

Yep, C++ is another infinite domain. Just last week, I learnt that ## is string concat operator in the preprocessor language.


Markdown formatting supported