Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mineo/enumerate_skip
enumerate extended to support manual advancement or skipping of the index
https://github.com/mineo/enumerate_skip
enumeration iteration python
Last synced: about 2 months ago
JSON representation
enumerate extended to support manual advancement or skipping of the index
- Host: GitHub
- URL: https://github.com/mineo/enumerate_skip
- Owner: mineo
- License: mit
- Created: 2015-01-04T15:48:08.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-04-05T12:24:37.000Z (over 3 years ago)
- Last Synced: 2024-11-13T23:14:42.890Z (about 2 months ago)
- Topics: enumeration, iteration, python
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
===============================
enumerate_skip
===============================This package provides 2 iterators, `enumerate_skip` and `enumerate_manual`, that
extend the behaviour of the standard libraries `enumerate` a bit.`enumerate_skip` has been extended with a `skip` method that makes sure the next
`index` yielded is the same as the current one. The word `skip` might not make
sense at first, but this function was written because I needed to not handle
some values yielded by an iterator, like::for index, obj in enumerate(...):
if obj.has_some_attr():
continue
# do something with object and index hereIf `index` in that example was printed to the user (or something similar), there
would be gaps. Using `enumerate_skip` instead, the above example could be
written as::it = enumerate_skip(...)
for index, obj in it:
if obj.has_some_attr():
it.skip()
continue
# do something with object and index here`enumerate_manual` works the other way around: you have to manually call
`advance` on it to increment the `index`::it = enumerate_manual(...)
for index, obj in it:
if obj.has_some_attr():
continue
# do something with object and index here
it.advance()