At 08:28 PM 4/25/2008, Kent Johnson wrote:
Dick Moores wrote:
I have the feeling that I've either forgotten (or never knew) some basic Python built-in or something, but in case I haven't, what's the best way to convert a list of integers to a string?

I dunno about 'best', but here is one way to do it:
''.join(map(str, intList))

Perhaps faster using iterator.imap() instead of map().

I suppose you meant
''.join(itertools.imap(str, intList))
And for intList = [0,1,2,3,4,5,6,7,8,9], this is 2X slower than ''.join(map(str, intList)) . But for intList = 1000*[0,1,2,3,4,5,6,7,8,9], ''.join(itertools.imap(str, intList)) has a very small edge.

Thanks, Kent, both of those are in my "never knew" category.

Dick



           ================================
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
Version 3.9 was released April 25!
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to