Python: Appending large number of elements to list, does memory usage double during resizing? -


let's assume i've empty python list , append elements it

sample_list = [] in xrange(2**36):    sample_list.append(str(i) + 'test') 

python list internally array keeps re-sizing when becomes full. when resizing happening large array, how memory usage of process work, doubles?

it double several times, each time 1 of appends pushes used space past threshold resizing. more efficient use 1 call extend:

sample_list.extend([str(i) + 'test' in xrange(2**36)]) 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -

r - Update two sets of radiobuttons reactively - shiny -