#python #sicp
Another common sequence processing operation is to select a subset of values
that satisfy some condition. List comprehensions can also express this pattern,
for instance selecting all elements of odds that evenly divide 25 .
>>> [ x for x in odds if 25 % x == 0 ] [1, 5]
If you want to change selection, open document below and click on "Move attachment"
2.3 Sequences statement, but instead part
of a list comprehension because it is contained within square brackets.
The sub-expression x+1 is evaluated with x bound to each element of
odds in turn, and the resulting values are collected into a list.
<span>Another common sequence processing operation is to select a subset of values
that satisfy some condition. List comprehensions can also express this pattern,
for instance selecting all elements of odds that evenly divide 25 .
>>> [x for x in odds if 25 % x == 0]
[1, 5]
The general form of a list comprehension is:
[<span><body><html> Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details