# File: timeTest3.py # # Comparing the running time of inserting a value in a random position # of a list versus inserting a random item into a dictionary. # import time import random REPS = 400000 # REPS = 10 SIZE = 100 random.seed() aList = [ 0 ] * SIZE aDict = {} start = time.time() for i in range (0, REPS): value = random.randint(1,REPS) index = random.randint(0,len(aList)) aList.insert(index,value) #index2 = random.randint(0, SIZE + i) #aDict[index2] = value finish = time.time() print("Elapsed time =", finish - start, "seconds")