On Python import time module and use time() to find the time before and after the execution of a for-loop that loops through range(1000) and appends each number to a list. Print the time taken for the execution of the loop.
import time
lst=[]
#taking the starting time
start=time.time()
#looping 1000 times and appending it to list
for i in range(1000):
lst.append(i)
#taking end time
end = time.time()
#finding total time
total=end-start
print("Time taken for loop execution ",total)
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME
Get Answers For Free
Most questions answered within 1 hours.