Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: Possible PEP - two dimensional arrays? Date: Wed, 8 Jun 2016 03:07:50 -0400 Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de KoNXZstuOPtrE9os2nmN9Ag7EXueTHVeHyiAjtYXkRUQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'static': 0.03; 'string.': 0.04; 'elements.': 0.05; 'float': 0.05; 'removes': 0.05; 'array.': 0.07; 'assignment': 0.07; 'subject:PEP': 0.07; 'subject:two': 0.07; 'closest': 0.09; 'finite': 0.09; 'grid': 0.09; 'integer,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple': 0.09; 'python': 0.10; 'jan': 0.11; 'arrays,': 0.16; 'arrays.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'removal,': 0.16; 'resizing': 0.16; 'wrote:': 0.16; 'string': 0.17; 'retrieval': 0.18; 'arrays': 0.22; 'function,': 0.22; 'int,': 0.22; 'parameter': 0.22; 'tuples': 0.22; 'programming': 0.22; 'elements': 0.23; 'unlike': 0.23; 'header:In- Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'parameters': 0.27; "skip:' 10": 0.28; 'currently,': 0.29; 'dictionary': 0.29; 'initialized': 0.29; 'array': 0.29; 'character': 0.29; 'returned': 0.32; 'class': 0.33; 'indexed': 0.33; 'languages': 0.34; 'lists': 0.34; 'list': 0.34; 'could': 0.35; 'instance': 0.35; 'library.': 0.35; 'lists.': 0.35; 'propose': 0.35; 'there': 0.36; 'created': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'space': 0.40; 'your': 0.60; 'received:96': 0.63; 'more': 0.63; 'saving': 0.70; 'flexible,': 0.84; 'float,': 0.84; 'subject:Possible': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-96-227-207-81.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: Xref: csiph.com comp.lang.python:109658 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