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

Mike Olson Mike.Olson at fourthought.com
Wed Sep 18 02:27:02 MDT 2002


On Tue, 2002-09-17 at 10:02, Ben Harding wrote:
> On 17 Sep 2002 at 10:51, Cameron Laird wrote:
> > > 		.
> > I'm actually fond of map and lambda.  For those following
> > along at home, let's make clear what a list comprehension
> > offers:
> >   string.join([str(item) for item in list], '; ')
> > or
> >   ', '.join([str(element) for element in list])
> 
> I _am_ following along at home.  I had no idea that I already knew 
> what a list comprehension was, so this was helpful.  But, I wonder 
> why the distinction between "item" and "element" in these two 
> statements.

I'm not surte what Cameron had in mind, but technically, there is no
difference.  As of Python 2.0 (I believe) string.join is implemented as 

def join(st,other):
  return other.join(st)

Which basically translates the first example into the second (except the
first joins with "; " as oppose to ", " of course)

Mike

> 
> Ben Harding
> --
> --------------------------------------------------
> -- Ben Harding              blh at hydrosphere.com --
> --       Hydrosphere Resource Consultants       --
> --       Hydrosphere Data Products              --
> --       1002 Walnut, Suite 200                 --
> --       Boulder CO 80302                       --
> --       http://hydrosphere.com/                --
> -- 303-443-7839 voice          303-442-0616 fax --
> --                                              --
> -- Publishing Natural Resources Data on CD ROM  --
> --  Consultants in Natural Resources Planning   --
> --------------------------------------------------
> 
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
-- 
Mike Olson                                Principal Consultant
mike.olson at fourthought.com                +1 303 583 9900 x 102
Fourthought, Inc.                         http://Fourthought.com 
PO Box 270590,                            http://4Suite.org
Louisville, CO 80027-5009, USA
XML strategy, XML tools, knowledge management




More information about the FRPythoneers mailing list