On 2007-09-15, Erik Jones <[EMAIL PROTECTED]> 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?
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to