[FRPythoneers] iterator like inject:into to generating comma-separated list

Sean Reifschneider jafo at tummy.com
Mon Sep 16 18:17:30 MDT 2002


On Mon, Sep 16, 2002 at 06:34:07PM -0500, Cameron Laird wrote:
>Is this it?
>  Python 1.5.2 (#2, Dec 30 1999, 23:29:24)  [GCC 2.7.2.3] on freebsd3
>  Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>  >>> my_list = ["a", "b", "c"]
>  >>> import string
>  >>> string.join(my_list, ",")
>  'a,b,c'
>  >>> string.join(my_list, ":")
>  'a:b:c'                                

Alternately:

   >>> list = [1, 'a', 2]
   >>> reduce(lambda x, y: str(x) + ',' + str(y), list)
   '1,a,2'

which will explicitly str() the arguments if they aren't already strings.

Sean
-- 
 What exactly would a "free, no-risk trial" of an on-line casino be?
                 -- Evelyn Mitchell, 1998
Sean Reifschneider, Inimitably Superfluous <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995.  Qmail, Python, SysAdmin



More information about the FRPythoneers mailing list