What is the difference between these two approaches?
import time
start_time = time.time()
node_to_visit = [4]
print("My program took", time.time() - start_time, "to run")
start_time = time.time()
node_to_visit = []
node_to_visit.append(4)
print("My program took", time.time() - start_time, "to run")
Output:
My program took 7.43865966796875e-05 to run
My program took 0.00012230873107910156 to run
4). If you want to time them try the timeit module. ...t = Timer('node_to_visit=[4]')andt1 = Timer('node_to_visit=[];node_to_visit.append(4)')