how to join array of integers?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Sep 16 18:35:23 EDT 2007


On Sun, 16 Sep 2007 19:25:22 +0100, Paul Rudin wrote:

>> The generator expression takes about twice as long to run, and in my
>> opinion it is no more readable. So what's the advantage?
> 
> If you do it with a decent size list they take more or less the same
> time. 

Did you try it, or are you guessing? What do you call a decent size?


> You'd presumably expect the generator to use less memory; which
> might be an advantage if you have large lists.

Unfortunately, Python doesn't make it as easy to measure memory use as it 
does to time snippets of code, so that's just a hypothetical.


> Isn't it odd that the generator isn't faster, since the comprehension
> presumably builds a list first and then iterates over it, whereas the
> generator doesn't need to make a list?

Who says it doesn't need to make a list? string.join() needs a sequence.


-- 
Steven.



More information about the Python-list mailing list