forked from fsr/python-lessons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should close issue fsr#18
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# erzeugt eine Liste welche jede Zahl n | ||
# von 0 bis 4 (4 nicht enthalten) n mal enthält | ||
list1 = [i for i in range(4) for _ in range(i)] | ||
|
||
# gleicher Code ohne Comprehension | ||
list2 = [] | ||
for i in range(4): | ||
for _ in range(i): | ||
l.append(i) | ||
|
||
list1 == list2 == [1,2,2,3,3,3] | ||
|
||
# löst einen NameError aus, weil | ||
# a erst durch die zweiten Schleife entsteht | ||
[i for i in range(a) for a in range(i)] | ||
|
||
# zählt für jede Zahl n von 0 bis 4 (4 nicht enthalten) | ||
# von 0 bis n-1, weil EXPRESSION erst nach der letzten | ||
# Schleife evaluiert wird | ||
list3 = [a for i in range(4) for a in range(i)] | ||
|
||
list3 == [0,0,1,0,1,2] |
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