Loop in a loop?
Paul Rubin
http
Thu Jan 17 13:39:25 EST 2008
Sacred Heart <scrdhrt 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.
More information about the Python-list
mailing list