[Tutor] list iteration [iteration and mutation?]

Chad Crabtree flaxeater at yahoo.com
Mon May 3 17:19:15 EDT 2004


> Right.  But there is a forth lesson to learn.
> 
> 4. Try a functional approach. e.g.:
> 
> filter(lambda i: predicate(i), lst)
> 
> or
> 
> [i for i in lst if predicate(i)]
> 
> So with your example:
> 
> >>> filter(lambda s: not s.startswith('m'), l)
> ['polly', 'dolly', 'pike']
> >>> [s for s in l if not s.startswith('m')]
> ['polly', 'dolly', 'pike']
> 

That's pretty cool.  I keep seeing cool tricks like
this but I can never think of them.  In addition I
have been unable to teach myself a functional
language.  Someday.  The neet thing is that is just
about as comprehensible as Haskell.  Which is
comprehensible like gabriels horn is comprehenisble.


	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 



More information about the Tutor mailing list