Created
December 28, 2015 23:38
-
-
Save xiantail/ef2fc241f9d4c8038402 to your computer and use it in GitHub Desktop.
Introducing Python / Chapter 12
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
from timeit import timeit | |
def make_list_1(): | |
result = [] | |
for value in range(1000): | |
result.append(value) | |
return result | |
def make_list_2(): | |
result = [value for value in range(1000)] | |
return result | |
print('time_list_1 takes', timeit(make_list_1, number=1000), 'sec') | |
print('time_list_2 takes', timeit(make_list_2, number=1000), 'sec') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment