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

spawgi at gmail.com spawgi at gmail.com
Thu Jan 26 23:34:47 CET 2012


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 this snippet, I would be very thankful.

Thanks and Regards,
Sumod


-- 
http://spawgi.wordpress.com
We can do it and do it better.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120127/1eebf97c/attachment.html>


More information about the Tutor mailing list