Skip to main content

Provides a utility for constructing generators out of an iterable that yield look-ahead (and/or “look-behind”) tuples.

Project description

Constructs a generator over the iterable yielding look-ahead (and/or “look-behind”) tuples. One tuple will be generated for each element value accessible from the iterator, containing that element and the number of elements specified just prior to and immediately after. When no such element exists, the None is used instead.

If one were to think of iterator as a list, this is would be similar to appending [None]*lookahead and prepending [None]*lookbehind, then iterating over and returning a sliding window of length lookbehind+1+ lookahead (except of course that instead of generating the such a list, this implementation generates (and caches) lookahead values only as needed).

lookahead() may be called with 1, 2, or 3 parameters:

Defaults to lookahead=1, lookbehind=0
lookahead(iterable, lookahead)
Defaults to lookbehind=0
lookahead(iterable, lookbehind, lookahead)
Notice that lookahead is now the 3rd parameter!

Example semantics:

yield (item, next)
lookahead(iterable, 2):
yield (item, next, next+1)
lookahead(iterable, 1, 2):
yield (prev, item, next, next+1)
lookahead(iterable, p, n):
yeild (prev, …, prev+p-1, item, next, …, next+n-1)

Project details

Release history Release notifications | RSS feed

This version


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lookahead, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size lookahead-1.0.tar.gz (2.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page