4 ms·
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 capa
by idank 13y ago
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.
- pdonis 13y agoDoes 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.
- thomasahle 13y agoTwo loops are still linear as long as they are not nested ;-)
- pdonis 13y agoOops, yes, good point. :)