How to use map

apardon at trout.vub.ac.be apardon at trout.vub.ac.be
Fri Mar 23 10:07:41 EST 2001


If f is a function and k, l and m are lists of the same length
then the following two are IMO more or less equivallent. (*)

  for i in range(len(m)):
    m[i] = f( k[i] , l[i] )

and

  m = map(f,k,l)


I was wondering should k, l and m now be lists of lists
of the same length and all sublists having the same
length too, if it would be possible to eliminate the
use of any loop and get the same result as

  for i in range(len(m)):
    for j in range(len(m[0])):
      m[i][j] = f( k[i][j] , l[i][j] )


(*) I know they are not entirely equivallent but for my
purpose they are equivallent enough

-- 
Antoon Pardon



More information about the Python-list mailing list