[Tutor] list issue.. i think

Steven D'Aprano steve at pearwood.info
Fri Dec 23 04:39:16 CET 2011


bruce wrote:
> hi.
> 
> got a test where i have multiple lists with key/values. trying to figure
> out how to do a join/multiply, or whatever python calls it, where i have a

Whatever Python calls what? You need to explain what *you* mean by "a 
join/multiply" before we can tell what you are referring to.

Perhaps start with a simple example?


> series of resulting lists/dicts that look like the following..
> 
> the number of lists/rows is dynamic..
> the size of the list/rows will also be dynamic as well.
> 
> i've looked over the py docs, as well as different potential solns..
> 
> psuedo code, or pointers would be helpful.
> 
> thanks...
> 
> test data
> a['a1']=['a1','a2','a3']
> a['a2']=['b1','b2','b3']
> a['a3']=['c1','c2','c3']


If you're indexing by key rather than by position, you need a dict, not a 
list. So:

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


> end test result::
> a1:a1,a2:b1,a3:c1
> a1:a2,a2:b1,a3:c1
> a1:a3,a2:b1,a3:c1

I don't even understand what that is supposed to mean.




-- 
Steven




More information about the Tutor mailing list