Question: InCodeFragment5.1,weperformanexperimenttocomparethelengthof a Python list to its underlying memory usage. Determining the sequence of array sizes requires a manual inspection of the output of that program.
InCodeFragment5.1,weperformanexperimenttocomparethelengthof a Python list to its underlying memory usage. Determining the sequence of array sizes requires a manual inspection of the output of that program. Redesign the experiment so that the program outputs only those values of k at which the existing capacity is exhausted. For example, on a system consistent with the results of Code Fragment 5.2, your program should output that the sequence of array capacities are 0, 4, 8, 16, 25, . . . .
import sys data=[] for k in range(n):
# provides getsizeof function
# NOTE: must fix choice of n # number of elements # actual size in bytes
a = len(data) b = sys.getsizeof(data) print( Length: {0:3d}; Size in bytes: {1:4d} .format(a, b)) data.append(None) # increase length by one
By Python
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
