[Tutor] Best way to convert list of ints to a string?
Dick Moores
rdm at rcblue.com
Sat Apr 26 07:57:52 CEST 2008
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!
More information about the Tutor
mailing list