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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -