[Tutor] Re: List Comprehensions again

Tom Jenkins tjenkins@devis.com
24 Jan 2002 13:37:17 -0500


On Thu, 2002-01-24 at 11:54, kevin parks wrote:
> I have never been able to get my head around list comprehension and desperately want too. I wish that there was a *good* little 2-3 page toot on list comprehensions that start from the very clearest and simplest examples and built up from there with nice explanations in between. The www.python.org web site is a bit terse for me and none of the books that i have on hand (save Mr.Chun's excellent tome, which is out of reach at the moment) cover list comprehensions which were too new at the time. I really feel like i need to know this as I am constantly working with lists that I want to transform in some way an element at a time. Does anyone know of such a toot? I hate to ask such a vague question. I know that it is easier to answer questions like: I have a a piece of code that does _____, but now it wont do ___, if i add ____ to the _____, see:
> 
> [insert code here]
> 
> etc..... Basically I am still using map and filter and lambda to do things cause he don't get the new list comprehension thing, yet I come across code that uses list comprehensions constantly and I sometimes don't know what I am looking at.
> 
> Anyone really got List comprehensions down cold or know off a good toot on the web? I would be grateful for any help in this matter. I need something that I can print out and stare at and type into the interpreter and really study.
> 
> best wishes,
> 

i came to python before list comprehensions.  it took me A LONG TIME to
understand map/filter/lambda... actually i'll say i still don't really
understand them.

when i first saw list comprehensions, i thought "I have NO CLUE what
this is doing".  then i started playing.  i took a map/lambda
combination and tried to rewrite it in list comprehension.  that
worked... now i can do fairly well with LC's

So that was a rambling way of saying... why don't you post some
map/lambdas and we'll LC 'em together.

(note I;ve found I learn by example)

-- 

Tom Jenkins
Development InfoStructure
http://www.devis.com