Question regarding a recent article on informit.com

Mel Wilson mwilson at the-wire.com
Thu Mar 20 15:32:25 CET 2003


In article <b5cfrh$f2q$1 at newsg4.svr.pol.co.uk>,
"Ben S" <bens at replytothegroupplease.com> wrote:
>Are there any good tutorials of examples of list comprehension use? In
>particular, I'm interested in how to replicate the functionality of
>reduce? Map and filter seem easy to do, though.

   Well, reduce isn't "intended" to return a list, so a list
comprehension wouldn't be a natural thing to replace it.

   I mean, if you had a list of numbers to total, you might
write

total = reduce (add2, my_list_of_numbers)

but you wouldn't start out by writing

total = [

and fill in the rest of the line with a list comprehension.
You wouldn't intend `total` to refer to a list.


        Regards.        Mel.




More information about the Python-list mailing list