Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109658

Re: Possible PEP - two dimensional arrays?

From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: Possible PEP - two dimensional arrays?
Date 2016-06-08 03:07 -0400
Message-ID <mailman.69.1465369688.2306.python-list@python.org> (permalink)
References <CACMigy1yXKuX0HCyAcE7MrWdC5DJhOMVtnxbcLVkU_Qw4MZsYg@mail.gmail.com> <nj8g8f$6dl$1@ger.gmane.org>

Show all headers | View raw


On 6/7/2016 8:17 PM, Harrison Chudleigh wrote:
> I was programming a computer game and found that while 1D arrays can be
> created using the module array, there is no module for two-dimensional
> arrays, unlike languages like C. Currently, the closest thing Python has to
> a 2D array is a dictionary containing lists.

A list of lists is standard if one is not using numpy, indexed as, for 
instance 'board[i][j]' A tuple of tuples can be used for static 2d 
array.  I expect people have also used a list of arrays, though for most 
games, the space saving is not enough, plus a list of list is more 
flexible, in that one can put a 'piece' on and 'square'.

> I propose that a module , 2DArray, be added to the standard library. This
> module will include:
> Assignment and retrieval on items on a two-dimensional, finite rectangular
> grid. Types are integer, float, character and string.
> Resizing the grid - parameters are old size and new size. Any new elements
> are initialized with a value of 0 for int, 0.0 for float and ' ' for string
> and character arrays.
> Removing elements. The parameter is the location. After removal, the value
> returned is 0 for int, 0.0 for float and ' ' for string and character
> arrays.
> A function, pop(), which removes elements from the grid and then returns
> them.

You could create your own class based on a list of arrays, and even 
publish it.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Possible PEP - two dimensional arrays? Terry Reedy <tjreedy@udel.edu> - 2016-06-08 03:07 -0400
  Re: Possible PEP - two dimensional arrays? wxjmfauth@gmail.com - 2016-06-08 01:13 -0700

csiph-web