newbie list question

Paul Rubin http
Sat Dec 6 07:49:13 EST 2003


Kamus of Kadizhar <yan at NsOeSiPnAeMr.com> writes:
> > difffav = [[f for f in new if f not in old] for new,old in
> > zip(fav,oldfav)]
> 
> Yes it does.  But I have no idea how.  :-(
> 
> I think it's going to take me a while to figure out what the above
> does....  :-)  Where do I find that in the FM?

Look up "list comprehension" in the index... also the "zip" function
in the library reference.  List comprehensions are a "functional" way
of expressing lists, like

   oddsquares = [x*x for x in (1,2,3,4,5) if x%2 == 1]

would set oddsquares to [1,9,25].  It will likely take a little
practice before this stuff rattles off your fingertips easily.




More information about the Python-list mailing list