python list/array question...

Bruno Desthuilliers onurb at xiludom.gro
Wed Jul 5 10:00:11 EDT 2006


bruce wrote:
> hi...
> 
> i'm trying to deal with multi-dimension lists/arrays

Python has lists (which AFAIK really are arrays not linked lists, but
they are called 'lists'). FWIW, this is in the fine manual.

> i'd like to define a multi-dimension string list, and then manipulate the
> list as i need... primarily to add lists/information to the 'list/array' and
> to compare the existing list information to new lists
> 
> i'm not sure if i need to import modules, or if the base python install i
> have is sufficient.

?????

importing modules doesn't require installing additional packages (unless
the modules you want to import are not part of the stdlib nor of your
application).

> an example, or pointer to examples would be good...

http://www.python.org/doc/

> i'd like
> 
>  define a[][]

No "define" statement in Python - as you would know if you had read the
fine manual.

>  #basically, i'd like a 3x3 array, where each element
>  #has one of the a,b,c items..
>  # |a1, b1, c1|
>  # |a2, b2, c2|
>  # |a3, b3, c3|
> 
>  a[1][1] = ['a1','b1','c1']

Python's list are zero-based (which is the common case). This is
mentionned in the fine manual.

>  a[1][2] = ['a2','b2','c2']
>  a[1][3] = ['a3','b3','c3']

a = [
['a1','b1','c1'],
['a2','b2','c2'],
['a3','b3','c3'],
]

or

a = []
a.append(['a1','b1','c1'])
a.append(['a2','b2','c2'])
a.append(['a3','b3','c3'])

(etc - cf the fine manual).

>  b = ['f','g','h']
>  v = ['f1','g1','h1']
> 
>  if a[1][2] == b
>    print 'good!'
> 
>  a[1][4] = b
> 
>  x = 4
>  g = ['p1','l1','g1']
> 
>  for i in range[g]
>   a[x][i] = g[i]
> 
> 
> these are the kinds of list/array functions i'd like to be able to
> accomplish
> 
> pointers/code samples/pointers to code would be helpful...

start here : http://www.python.org/doc/

> and yeah. i've been looking via google...

Really ?



-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list