Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 040a276

Browse files
committed
update list comprehension readme
1 parent 6ff45c8 commit 040a276

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎comprehension/list/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ In a UNIX terminal, run:
77

88
```
99
time python list-append-loop.py
10-
```
10+
1111
real 0m11.381s
1212
user 0m10.553s
1313
sys 0m0.824s
14+
```
1415

1516
```
1617
time python list-comp.py
17-
```
18+
1819
real 0m4.228s
1920
user 0m3.428s
2021
sys 0m0.800s
22+
```
2123

2224

2325
Here we see that the list comprehension was almost 3x as fast
@@ -31,24 +33,32 @@ numbers with the range() function, we can actually just cast the result
3133
of the range() function to a list and get even faster speed than the
3234
list comprehension.
3335

36+
```
37+
time python cast-list.py
38+
39+
real 0m2.988s
40+
user 0m2.176s
41+
sys 0m0.812s
42+
```
43+
3444
To show a more practical example where you can't just cast it:
3545

3646
```
3747
time python list-append-loop2.py
38-
```
3948
4049
real 0m29.756s
4150
user 0m28.875s
4251
sys 0m0.880s
52+
```
4353

4454

4555
```
4656
time python list-comp2.py
47-
```
4857
4958
real 0m21.932s
5059
user 0m21.031s
5160
sys 0m0.900s
61+
```
5262

5363
In this practical example, we see that the list comprehension finished
5464
in about 2/3 of the time it took the for loop append() method, still

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /