[melbourne-pug] array matching

Filip filipz at 3g.nec.com.au
Thu Apr 29 21:11:59 EDT 2010


You could use dictionary of lists

 

test = {

            A: [1, 3],

            B: [2, 4]

}

 

print test[A]

[1, 3]

 

test[A].append(5)

 

print test[A]

[1, 3, 5]

 

Cheers,

 

Fil

  _____  

From: melbourne-pug-bounces+filipz=3g.nec.com.au at python.org
[mailto:melbourne-pug-bounces+filipz=3g.nec.com.au at python.org] On Behalf Of
Bill Jordan
Sent: Friday, 30 April 2010 3:58 AM
To: python-dev at python.org; python-list at python.org; bangpypers at python.org;
melbourne-pug at python.org; portland at python.org
Subject: [melbourne-pug] array matching

 

Hey guys,

 

I am sorry if this is not the right list to post some questions. I have a
simple question please and would appreciate some answers as I am new to
Python.

 

I have 2 D array: test = [[A,1],[B,2],[A,3][B,4]]

I want to arrang this array in different arrays so each one will have what
is attached to. For example I want the output:

 

A =[1,3] and B=[2,4]

 

Thanks,

Bill

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100430/0ca5c003/attachment-0001.html>


More information about the Python-list mailing list