Created
December 24, 2022 07:37
-
-
Save raghavmri/330de15d51028d38e5057e49dad544ff to your computer and use it in GitHub Desktop.
Added Two lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
a = [] | |
b = [] | |
for i in range(1000000): # Adding 1000000 element to both the lists | |
a.append(i) | |
b.append(i+10) | |
start_time = time.time() | |
c = a+b # Adding The lists using + operator | |
print("Time Taken To Concatenate using + Operator {}s".format(round(time.time()-start_time, 4))) | |
start_time = time.time() | |
d = a.extend(b) # Adding the lists using the extend method | |
print("Time Taken To Concatenate using extend Method {}s".format( | |
round(time.time()-start_time, 4))) | |
start_time = time.time() | |
for i in b: # Adding the lists using the for loop | |
a.append(i) | |
print("Time Taken To Concatenate using For Loop Method {}s".format( | |
round(time.time()-start_time, 4))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment