Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list slicing
- import matplotlib.pyplot as plt
- import random
- from datetime import datetime
- lst = []
- x = ["O", "A"]
- for i in range(500000):
- lst.append(random.choice(x))
- size = 50000
- x_axis = []
- y_axis = []
- while size<=500000:
- temp_list = lst[:size]
- t1 = datetime.now()
- while temp_list:
- temp_list = temp_list[1:]
- t2 = datetime.now()
- diff = (t2-t1).total_seconds()
- print(size, diff)
- x_axis.append(size)
- y_axis.append(diff)
- size+=50000
- plt.plot(x_axis, y_axis)
- plt.title("List Slicing")
- plt.xlabel("Size")
- plt.ylabel("Time")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment