how to join array of integers?
Grant Edwards
grante at visi.com
Sat Sep 15 12:25:15 EDT 2007
On 2007-09-15, Erik Jones <erik at myemma.com> wrote:
>>> 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?
The generator avoids creating the intermediate list -- it
generates the intermediate values on the fly. For short
sequences it probably doesn't matter much. For a very long
list it's probably noticable.
--
Grant Edwards grante Yow! Mr and Mrs PED, can I
at borrow 26.7% of the RAYON
visi.com TEXTILE production of the
INDONESIAN archipelago?
More information about the Python-list
mailing list