Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-27 Thread Alan Gauld
On 27/01/12 06:44, Andre' Walker-Loud wrote: ... I have only had one programming class, and that was 15 years ago or so, > ...so these are not issues I am aware of. I often find myself joining strings (and have mostly used + to do it). String addition is OK in some languages, or at least bet

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-27 Thread Blockheads Oi Oi
On 27/01/2012 06:44, Andre' Walker-Loud wrote: Hi Steven, (5) When assembling strings from substrings, never use repeated concatenation using + as that can be EXTREMELY slow. Use str.join to build the string in one assignment, instead of multiple assignments. Your code shown above is *very*

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread Andre' Walker-Loud
Hi Steven, > (5) When assembling strings from substrings, never use repeated concatenation > using + as that can be EXTREMELY slow. Use str.join to build the string in > one assignment, instead of multiple assignments. > > Your code shown above is *very* inefficient and will be PAINFULLY slow i

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread spawgi
Hello Steven, Thanks a lot for the detailed answer. I will implement your suggestions. Really appreciate it. Thanks and Regards, Sumod On Fri, Jan 27, 2012 at 4:34 AM, Steven D'Aprano wrote: > spa...@gmail.com wrote: > >> Hello, >> >> My code is - >> >> l = len(m) >> item = str(m[1]) >> for i i

Re: [Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread Steven D'Aprano
spa...@gmail.com wrote: Hello, My code is - l = len(m) item = str(m[1]) for i in range(2,l): item = item + "-" + str(m[i]) This code is part of a bigger function. It works fine. But I am not happy with the way I have written it. I think there is a better (Pythonic) way to rewrite it. If an

[Tutor] Pythonic way of concatenation of elements in an array

2012-01-26 Thread spawgi
Hello, My code is - l = len(m) item = str(m[1]) for i in range(2,l): item = item + "-" + str(m[i]) This code is part of a bigger function. It works fine. But I am not happy with the way I have written it. I think there is a better (Pythonic) way to rewrite it. If anyone knows how to improve