how to join array of integers?

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


On Sep 15, 2007, at 8:56 AM, Arnau Sanchez wrote:

> js escribió:
>
>>> On 9/15/07, Summercool <Summercoolness at gmail.com> 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])

Why is that?  That entire expression must be evaluated to obtain the  
result, so what is the advantage of using a generator comprehension  
v. a list comprehension?





More information about the Python-list mailing list