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

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -