[Python-ideas] Syntax idea for 2D lists\arrays

Stephan Houben stephanh42 at gmail.com
Thu Mar 15 07:21:47 EDT 2018


I'd just do this, which works today:

==================
import numpy
import io

ar = numpy.loadtxt(io.StringIO("""
1   5   9   155
53  44  44  34
"""))
==================

Of course, this is only worth the trouble if you
are somehow loading a very large matrix.
(And then, are you sure you want to embed it in your code?)

Stephan


2018-03-15 6:15 GMT+01:00 Steven D'Aprano <steve at pearwood.info>:

> On Thu, Mar 15, 2018 at 01:32:35AM +0100, Mikhail V wrote:
>
> > Idea is a concept for 2D arrays/lists syntax, which should simplify
> > some editing boilerplate while working with arrays and improve
> > readability for bigger arrays.
>
> I don't understand; we already have perfectly good syntax for working
> with 2D arrays.
>
> > Lets start with a simple list example :
> >
> > L ===
> >     1   5   9   155
> >     53  44  44  34
> >
> > returns a 2d list:
> > [[1, 5, 9, 155], [53, 44, 44, 34]]
>
> We already have:
>
> L = [[1, 5, 9, 155], [53, 44, 44, 34]]
>
> which is more compact (one line rather than two) and explicitly delimits
> the start and end of each list. Like everything else in Python, it uses
> commas to separate items, not whitespace. If you prefer:
>
> L = [[1, 5, 9, 155],
>      [53, 44, 44, 34]]
>
>
> Using spaces to separate items has the fatal flaw that it cannot
> distinguish
>
>     x - y 0  # two items, the expression `x - y` and the integer 0
>
> from:
>
>    x - y 0  # three items, `x`, `-y`, and 0
>
>
> making it ambiguous. I stopped reading your post once I realised that.
>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180315/00a92c08/attachment.html>


More information about the Python-ideas mailing list