Skip to content

Python code snippet – How to use enumerate instead of range and len?

using enumerate instead of range or len
a = [f(n) for n, _ in enumerate(L)]

using range and len
a = [f(n) for n in range(len(L))]
See also  String formatting in Python

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.