Python strings question (vertical stack)

J. Clifford Dyer jcd at sdf.lonestar.org
Tue Nov 20 22:09:32 EST 2007


On Tue, 2007-11-20 at 13:59 -0800, John Machin wrote:
> On Nov 21, 7:15 am, Farshid Lashkari <n... at spam.com> wrote:
> > J. Clifford Dyer wrote:
> > > I think you mean '\n'.join([string1,string2,string3])
> >
> > > You actually do want the \ to do its thing in this case.
> >
> > Yeah, my brain must still be asleep. Thanks for waking it up :)
> 
> You're not alone :-)
> 
> >>> a = """
> ... x
> ... y
> ... z
> ... """
> >>> a
> '\nx\ny\nz\n'
> >>> '\n'.join(['x', 'y', 'z'])
> 'x\ny\nz'
> >>>

It's true: my solution did not match the exact specification given by
the OP's code, but 1) I was responding to Farshid Lashkari's slip and 2)
It does what the OP was ultimately asking for--it stacks the results
vertically.  My brain was not asleep, I was just not interested in the
other, largely irrelevant part of the OP's question.  If he wants a new
line at the beginning and end, I'm sure he can figure out how to do it.
I don't need to jump through those hoops for him.

Cheers,
Cliff






More information about the Python-list mailing list