Loop in a loop?

Sacred Heart scrdhrt at gmail.com
Fri Jan 18 11:25:06 CET 2008

On Jan 17, 7:39 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Sacred Heart <scrd... at gmail.com> writes:
> > array1 = ['one','two','three','four']
> > array2 = ['a','b','c','d']
> > I want to loop through array1 and add elements from array2 at the end,
> > so it looks like this:
> > one a
> > two b
> > three c
> > four c
> The "functional" style is to use the zip function that someone
> described.  The old-fashioned way is simply:
>    n = len(array1)
>    for i in xrange(n):
>        print array1[i], array2[i]
> You can modify this in various ways if the lengths of the lists are
> not equal.  E.g.

Thank you Paul, and everybody else contributing with answers of
various complexity. Although a whole bunch of them was way too complex
for my simple problem, but that's ok.

I now know how to use map and zip, and also learned some tips and


All the best,

More information about the Python-list mailing list