Skip to main content

views – efficient tools for generators and sequences

The views module provides additions to the existing python comprehensions and generator expressions. (Chained) sequence views can be made using seq and generators can be chained with gen, as shown in the examples below.

Any feedback or suggestions are very welcome.

Getting Started

Requirements

  • Python 3.6+

Installation

The package can be installed with pip (make sure you have it installed):

pip3 install git+http://github.com/k7hoven/views

Or if your default python is Python 3:

pip install git+http://github.com/k7hoven/views

Basic Usage

Basic introductory examples here, but they should get you started.

Sequence view comprehension syntax

You can change chain single objects and sequences into one sequence view. Use :: just like you would use * in tuple (un)packing. The resulting object supports slicing and indexing.

Example:

>>> from views import seq
>>> seq[::range(3), None, ::"abc", "Hi!"]
<sequence view 8: [0, 1, 2, None, 'a', 'b', 'c', 'Hi!'] >
>>> seq[::range(100)]
<sequence view 100: [0, 1, 2, 3, 4, ..., 96, 97, 98, 99] >

Generator comprehension syntax

Use like seq. The resulting object is a generator.

Example:

>>> from views import gen
>>> list(gen[::range(3), 3, 4, ::range(5,7), 7])
[0, 1, 2, 3, 4, 5, 6, 7]

Chaining sequences and generators/iterables

You can chain an arbitrary number of sequences with seq.chain(*sequences) and of generators with gen.chain(*iterables). The latter is equivalent to itertools.chain(*iterables).

Example:

>>> from views import seq, gen
>>> seq.chain([1, 2, 3], [4, 5, 6])
<sequence view 6: [1, 2, 3, 4, 5, 6] >
>>> list(gen.chain([1, 2, 3], [4, 5, 6]))
[1, 2, 3, 4, 5, 6]

Have fun!

Changelog

0.3.0 (2017-10-10)

  • Add seq.chain(*sequences) and gen.chain(*iterables)

  • Some speed optimizations, especially to seq.

0.2.0 (2017-09-11)

  • LengthChangedError is now a subclass of RuntimeError.

  • Minor optimizations to seq and gen.

0.1.0 (2017-06-06)

  • First version

Metadata

Release files for views 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for views 0.3
File Size Uploaded Provenance
views-0.3.tar.gz 4.7 kB Without provenance Details

Release files / views-0.3.tar.gz

Download URL views-0.3.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
17f60ecbc213d5aaa8f5359973ab8840071123547e1897cae2f6e762b62dcd68
BLAKE2b-256 checksum
How to use checksums
1bd95598d590f9467c364704397cbb0ebc9b33481b84e947c2af31cc1dc9fa11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for views 0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page