Re:Efficient String Concatenation in Python
by idank on Saturday September 07, 2013 @03:57PM
(#6346367)
Does join scan the entire input to know the exact size and allocate that at the start? Doesn't it do the usual thing for resizing and that is to double the capacity? A generator will save a temporary list, it will however result in a lot of overhead for the generator switches. It might be beneficial if the input is really big.
[ Parent
| on HN ]
Re:Efficient String Concatenation in Python
by pdonis on Saturday September 07, 2013 @05:16PM
(#6346660)
Does join scan the entire input to know the exact size and allocate that at the start?
No, because that would make the algorithm quadratic again (one loop for the scan, second loop for the concatenation), and the whole point of the join idiom, as recommended by the Python documentation, is to avoid a quadratic algorithm.
Re:Efficient String Concatenation in Python
by thomasahle on Saturday September 07, 2013 @05:21PM
(#6346672)
Two loops are still linear as long as they are not nested ;-)