Re: array matching
Bill Jordan wrote: 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 Did you try anything before asking ? this is a pretty simple problem. test = [['A',1],['B',2],['A',3], ['B',4]] arranged ={} # dictionary containing the arranged arrays for name, value in test: # you better be sure all arrays contain only 2 elements if name in arranged: arranged[name].append(value) else: arranged[name] = [value] print arranged out: {'A': [1, 3], 'B': [2, 4]} JM -- http://mail.python.org/mailman/listinfo/python-list
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: array matching
Bill Jordan wrote: 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] Build a dict of lists, ie the key is the first member of the sublist and the value is a list of second members of the sublist. -- http://mail.python.org/mailman/listinfo/python-list
Re: array matching
On 29-Apr-10 14:46 PM, MRAB wrote: Bill Jordan wrote: 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] Build a dict of lists, ie the key is the first member of the sublist and the value is a list of second members of the sublist. You might consider numpy, which is designed for arrays. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
RE: [melbourne-pug] array matching
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...@python.org [mailto:melbourne-pug-bounces+filipz=3g.nec.com...@python.org] On Behalf Of Bill Jordan Sent: Friday, 30 April 2010 3:58 AM To: python-...@python.org; python-list@python.org; bangpyp...@python.org; melbourne-...@python.org; portl...@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 -- http://mail.python.org/mailman/listinfo/python-list
Re: [melbourne-pug] array matching
Anyone responding to this thread, please delete python-dev and gmane.comp.python.dev from the followup list of where your response is sent. It should never have been part of this overly cross-posted thread. -- http://mail.python.org/mailman/listinfo/python-list