Skip to main content

views

Project description

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

Project details


Release history Release notifications | RSS feed

This version

0.3

Download files

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

Source Distribution

views-0.3.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file views-0.3.tar.gz.

File metadata

  • Download URL: views-0.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for views-0.3.tar.gz
Algorithm Hash digest
SHA256 17f60ecbc213d5aaa8f5359973ab8840071123547e1897cae2f6e762b62dcd68
MD5 f0212f66828a308a0408f9ef325c2eae
BLAKE2b-256 1bd95598d590f9467c364704397cbb0ebc9b33481b84e947c2af31cc1dc9fa11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page