Standard lib version of something like enumerate() that takes a max count iteration parameter?

Malcolm Greene python at bdurham.com
Wed Jun 14 14:09:43 EDT 2017


Wondering if there's a standard lib version of something like
enumerate() that takes a max count value?
Use case: When you want to enumerate through an iterable, but want to
limit the number of iterations without introducing if-condition-break
blocks in code.
Something like:

for counter, key in enumerate( some_iterable, max_count=10 ):
    <loop logic here>

Thank you,
Malcolm



More information about the Python-list mailing list