On Fri, Oct 26, 2012 at 09:49:50AM +0200, Ulrich Eckhardt wrote: > Hi! > > General advise when assembling strings is to not concatenate them > repeatedly but instead use string's join() function, because it > avoids repeated reallocations and is at least as expressive as any > alternative. > > What I have now is a case where I'm assembling lines of text for > driving a program with a commandline interface. In this scenario, > I'm currently doing this: > > args = ['foo', 'bar', 'baz'] > line = ' '.join(args) + '\n'
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 -- http://mail.python.org/mailman/listinfo/python-list