[Python-ideas] Add a datatype collections.ListView

Nathaniel Smith njs at pobox.com
Thu Apr 17 18:28:45 CEST 2014


On Thu, Apr 17, 2014 at 4:49 PM, David Mertz <mertz at gnosis.cx> wrote:
> What I'd really like is a "ListView" that acts something like NumPy's
> non-copying slices.  However numpy, of course, only deals with arrays and
> matrices of uniform numeric types.  I want a non-copying "slice" of a list
> of generic Python objects.

FWIW, numpy arrays do indeed have to be of uniform type, but one of
the supported uniform types is "arbitrary Python object".

In [1]: a = np.array([1, "hello", None])

In [2]: a
Out[2]: array([1, 'hello', None], dtype=object)

In [3]: a[1:]
Out[3]: array(['hello', None], dtype=object)

There are other trade-offs though, e.g., no .append() or .find() methods.

-n

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org


More information about the Python-ideas mailing list