how to join array of integers?

Erik Jones erik at myemma.com
Sat Sep 15 12:26:23 EDT 2007


On Sep 15, 2007, at 11:07 AM, Grant Edwards wrote:

> On 2007-09-15, Arnau Sanchez <arnau at ehas.org> wrote:
>
>>>> in Python... is the method to use ",".join() ?  but then it
>>>> must take a list of strings... not integers...
>>>>
>>>> any fast method?
>>
>>> print ''.join([str(i) for i in [1,2,3]])
>>
>> It's better to use generator comprehension instead of LC:
>>
>> ",".join(str(i) for i in [1, 2, 3])
>>
>> Or, if you happen to like the itertools modules:
>>
>> from itertools import imap
>> ",".join(imap(str, [1, 2, 3]))
>
> It's nice people have invented so many ways to spell the
> builting "map" ;)
>
>>>> ",".join(map(str,[1,2,3]))
> '1,2,3'

IIRC, map's status as a builtin is going away.

Erik Jones

Software Developer | Emma®
erik at myemma.com
800.595.4401 or 615.292.5888
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com





More information about the Python-list mailing list