A REALLY COOL PYTHON FEATURE:

Martijn Faassen m.faassen at vet.uu.nl
Thu May 11 07:56:59 EDT 2000


Courageous <jkraska1 at san.rr.com> wrote:

> While all the oldtimers here already know this, I thought
> I might share something really cool with some of my newbie
> peers.... :)

>>>> somenames = ["fred", "barney", "wilma", "betty"]
>>>> reallycool = reduce ( lambda x, y: x+", "+y, somenames )
>>>> reallycool
> 'fred, barney, wilma, betty'
>>>> 

> Check that out. Do you know what a royal pain in the ass
> it is in most languages to do this? It's a godawful pain
> in the ass, let me tell you. And there it is, in all it's
> glory:

> reduce ( lambda x, y: x+", "+y, somenames )

It's actually pretty easy in Python, too. :) (you think all this
reducing and lambda-ing is *easy*?)

import string
string.join(["foo", "bar", "baz"], ", ")

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list