Skip to content

Commit 0cebd2b

Browse files
Refactored code: for-loop for beginner readability
1 parent ffe4ae0 commit 0cebd2b

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

scripts/06_execution_time.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
"""
2-
ExecutionTime
3-
4-
This class is used for timing execution of code.
5-
6-
For example:
7-
8-
timer = ExecutionTime()
9-
print 'Hello world!'
10-
print 'Finished in {} seconds.'.format(timer.duration())
11-
12-
"""
13-
14-
151
import time
162
import random
173

@@ -26,9 +12,12 @@ def duration(self):
2612

2713
# ---- run code ---- #
2814

29-
3015
timer = ExecutionTime()
31-
sample_list = list()
32-
my_list = [random.randint(1, 888898) for num in
33-
range(1, 1000000) if num % 2 == 0]
16+
sample_list = []
17+
18+
for num in range(1, 1000000):
19+
if num % 2 == 0:
20+
random_number = random.randint(1, 888898)
21+
sample_list.append(random_number)
22+
3423
print('Finished in {} seconds.'.format(timer.duration()))

0 commit comments

Comments
 (0)