Explore the time required to remove an item

121 views 7:52 am 0 Comments March 14, 2023

Explore the time required to remove an item from a given index and graph the results.
You could try having the x axis be the size of the list and the y axis be the time required
to remove index 0
Explore the time required to insert an item at the beginning of a list of N size and graph
the results
The x axis could be the size of the list and the y axis be the time required
(install the matplotlib module)
def compute_time_to_add(list_to_add_to, item):
start = time.perf_counter()
list_to_add_to.append(item)
end = time.perf_counter()
return end-start
timings = []
some_list = []
values =
range(10_000_000)
for n in values:
timings.append(compute_time_to_add(some_list
, n))
plt.plot(values
, timings)
plt.show()