Skip to content

Commit 1c3c660

Browse files
committed
clarified the set comoprehensions lab a bit
1 parent ddbcc1d commit 1c3c660

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

slides_sources/source/exercises/comprehensions_lab.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,19 @@ divisible 2, 3 and 4.
232232

233233
a. Do this with one set comprehension for each set.
234234

235-
b. What if you had a lot more than 3? -- Don't Repeat Yourself (DRY)
235+
b. What if you had a lot more than 3? -- Don't Repeat Yourself (DRY).
236236

237-
- create a sequence that holds all three sets
237+
- create a sequence that holds all the divisors you might want --
238+
could be 2,3,4, or could be any other arbitrary divisors.
238239

239240
- loop through that sequence to build the sets up -- so no repeated code.
241+
you will end up with a list of sets -- one set for each divisor in your
242+
sequence.
243+
244+
- The idea here is that when you see three (Or more!) lines of code that
245+
are almost identical, then you you want to find a way to generalize
246+
that code and have it act on a set of inputs, so the actual code is
247+
only written once.
240248

241249
c. Extra credit: do it all as a one-liner by nesting a set comprehension
242250
inside a list comprehension. (OK, that may be getting carried away!)

0 commit comments

Comments
 (0)