better way for ' '.join(args) + '\n'?

Ramchandra Apte maniandram01 at gmail.com
Sat Nov 3 04:26:09 EDT 2012


On Saturday, 27 October 2012 03:12:31 UTC+5:30, Tycho Andersen  wrote:
> On Fri, Oct 26, 2012 at 05:36:50PM -0400, Dave Angel wrote:
> 
> > On 10/26/2012 05:26 PM, Tycho Andersen wrote:
> 
> > > Assuming it's the length of the list that's the problem, not the
> 
> > > length of the strings in the list...
> 
> > >
> 
> > > args = ['foo', 'bar', 'baz']
> 
> > > args[-1] = args[-1] + '\n'
> 
> > > line = ' '.join(args)
> 
> > >
> 
> > > \t
> 
> > 
> 
> > Main problem with that is the trailing space before the newline.  If
> 
> > that's not a problem, then fine.
> 
> 
> 
> What trailing space before the newline? The other solutions have it,
> 
> the above does not. However, the above does mutate args, which isn't
> 
> all that great. Alas, if you want the performance of mutable
> 
> structures, you're probably going to have to mutate something. (In any
> 
> case, it's easy enough to change it back, though ugly.)
> 
> 
> 
> > Not sure why we try so hard to optimize something that's going to take
> 
> > negligible time.
> 
> 
> 
> The same reason some people enjoy sporting events: it's fun :-)
Me too
> 
> 
> 
> \t



More information about the Python-list mailing list