Newbie: How do I implement an 2 element integer array in Python.?
Rainer Deyke
root at rainerdeyke.com
Wed Oct 11 19:59:22 EDT 2000
"Aahz Maruch" <aahz at panix.com> wrote in message
news:8s2608$2da$1 at panix3.panix.com...
> In article <7U%E5.61379$g6.27618408 at news2.rdc2.tx.home.com>,
> Rainer Deyke <root at rainerdeyke.com> wrote:
> ><jbranthoover at my-deja.com> wrote in message
> >news:8s1s48$89a$1 at nnrp1.deja.com...
> >>
> >> What is the syntax for creating a 2 element integer array? I
> >> have looked at the Array Module documentation, but I am afraid that I
> >> don’t quite understand it. In Basic I would do something like:
> >>
> >> Dim MyArray(100,16)
> >
> >In Python 1.6 and above, list comprehensions are probably your best bet.
> >
> >MyArray = [[0 for i in range(16)] for j in range(100)]
> >MyArray[5][4] = 7
>
> Why zero rather than None?
I think BASIC initializes to 0 (although I could be wrong here). Therefore
0 is most consistent with the original poster's experience. There are cases
where None is the better choice, but there are also cases where 0 is
superior (example: the array is used to store accumulators).
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list