Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32236
| Date | 2012-10-26 16:42 -0500 |
|---|---|
| From | Tycho Andersen <tycho@tycho.ws> |
| Subject | Re: better way for ' '.join(args) + '\n'? |
| References | <utrpl9-udk.ln1@satorlaser.homedns.org> <20121026212602.GE25893@ccapuser-ubuntu.WICOURTS.GOV> <508B0272.2020003@davea.name> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2907.1351287734.27098.python-list@python.org> (permalink) |
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 :-) \t
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
better way for ' '.join(args) + '\n'? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-10-26 09:49 +0200
Re: better way for ' '.join(args) + '\n'? Peter Otten <__peter__@web.de> - 2012-10-26 10:58 +0200
Re: better way for ' '.join(args) + '\n'? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-26 09:36 +0000
Re: better way for ' '.join(args) + '\n'? Hubert Grünheidt <hgruenheidt@t-online.de> - 2012-10-26 18:21 +0200
Re: better way for ' '.join(args) + '\n'? Tycho Andersen <tycho@tycho.ws> - 2012-10-26 16:26 -0500
Re: better way for ' '.join(args) + '\n'? Dave Angel <d@davea.name> - 2012-10-26 17:36 -0400
Re: better way for ' '.join(args) + '\n'? Tycho Andersen <tycho@tycho.ws> - 2012-10-26 16:42 -0500
Re: better way for ' '.join(args) + '\n'? Ramchandra Apte <maniandram01@gmail.com> - 2012-11-03 01:26 -0700
Re: better way for ' '.join(args) + '\n'? Ramchandra Apte <maniandram01@gmail.com> - 2012-11-03 01:26 -0700
Re: better way for ' '.join(args) + '\n'? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-10-27 11:26 +0200
RE: better way for ' '.join(args) + '\n'? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-29 22:28 +0000
csiph-web