Created
August 15, 2018 04:01
-
-
Save domodomodomo/d531ed624396313d3d5a0fdb5d62b0bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 random | |
import time | |
N = 100000 | |
lst1 = [random.randint(0, 9) for _ in range(N)] | |
lst2 = lst1.copy() | |
# insert | |
start1 = time.time() | |
lst = lst1 | |
new_lst = [] | |
while lst: | |
e = lst.pop() | |
if e % 2 == 0: | |
new_lst.insert(0, e) | |
end1 = time.time() | |
# append, reverse | |
start2 = time.time() | |
lst = lst1 | |
new_lst = [] | |
while lst: | |
e = lst.pop() | |
if e % 2 == 0: | |
new_lst.append(e) | |
else: | |
new_lst.reverse() | |
end2 = time.time() | |
# | |
print('insert:', end1 - start1) | |
print('append, reverse:', end2 - start2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment