[Tutor] Iterating two one dimensional lists to create a multidemsional array

S Potter f8lcoder at hotmail.com
Sat Oct 11 04:45:11 CEST 2008


OK I'm still new to the python list / array deal. I'm having problems with something very simple that I could accomplish in C++ but
for some reason I'm not grasping it python.

Here is my example psuedo code:

I have two lists:

items = ['roses','violets','sugar','so']

and

attributes = ['red','blue','sweet','you']

I have a variable:

action = 'are'

>From the above lists I would like to populate a multi dimensional array that would be like this;

poem ={ ['roses','are red'],
              ['violets','are blue'],
              ['sugar','are sweet']
              ['so','are you'] }

I'm assuming I would need two separate loops once through list(items) and then through list(attributes) and would have to concatenate variable(action) + str(attributes[0]).

But I'm having a severe brain squeeze right now and cannot get my code to work as desired.

Could someone please show me what the code should look like?

I know this is very elementary, I also know I can accomplish this in other languages but the objective is to
get my head around the python version.

Your help would be greatly appreciated.

Thanks





_________________________________________________________________
Want to do more with Windows Live? Learn “10 hidden secrets” from Jamie.
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081010/233e73b2/attachment.htm>


More information about the Tutor mailing list