@@ -38,28 +38,27 @@ Programming is hard when we have to juggle many code elements of each type at
3838the same time. Good programming is about managing these three elements so that
3939the developer is only required to think about a handful of them at a time. For
4040example we might collect many integer variables into a list of integers or
41- build a big function out of smaller ones. While we have natural ways to manage
42- data and functions, control flow presents more of a challenge.
41+ build a big function out of smaller ones.
4342
4443We organize our data into **data structures ** like lists, dictionaries, or objects
4544in order to group related data together -- this allows us to manipulate large
4645collections of related data as if we were only manipulating a single entity.
4746
48- We **build large functions out of smaller ones **; enabling us to break up a
47+ We **build large functions out of smaller ones **, enabling us to break up a
4948complex task like doing laundry into a sequence of simpler tasks.
5049
5150.. code ::
5251
5352 def do_laundry(clothes):
54- wet_clothes = wash(clothes, coins )
55- dry_clothes = dry(wet_clothes, coins )
53+ wet_clothes = wash(clothes)
54+ dry_clothes = dry(wet_clothes)
5655 return fold(dry_clothes)
5756
58- ** Control flow is more challenging **; how do we break down complex control flow
59- into simpler pieces that fit in our brain? How do we encapsulate commonly
60- recurring patterns?
57+ While we have natural ways to manage data and functions, ** control flow presents more of a challenge **.
58+ How do we break down complex control flow into simpler pieces that fit in our brain?
59+ How do we encapsulate commonly recurring patterns?
6160
62- Lets motivate this with an example of a common control structure, applying a
61+ Let's motivate this with an example of a common control structure, applying a
6362function to each element in a list. Imagine we want to download the HTML
6463source for a number of webpages.
6564
@@ -71,7 +70,6 @@ source for a number of webpages.
7170 html_texts = []
7271 for item in urls:
7372 html_texts.append(urlopen(item))
74- return html_texts
7573
7674 Or maybe we want to compute the Fibonacci numbers on a particular set of
7775integers
@@ -82,7 +80,6 @@ integers
8280 fib_integers = []
8381 for item in integers:
8482 fib_integers.append(fib(item))
85- return fib_integers
8683
8784 These two unrelated applications share an identical control flow pattern. They
8885apply a function (``urlopen `` or ``fib ``) onto each element of an input list
@@ -156,8 +153,8 @@ Most programmers however don't know about the many cousins of
156153 >>> groupby(len, names)
157154 {3: ['Bob', 'Dan'], 5: ['Alice', 'Edith', 'Frank'], 7: ['Charlie']}
158155
159- Groupby collects each element of a list into sublists determined by the value
160- of a function. Lets see ``groupby `` in action again, grouping numbers by
156+ `` groupby `` collects each element of a list into sublists determined by the value
157+ of a function. Let's see ``groupby `` in action again, grouping numbers by
161158evenness.
162159
163160.. code ::
@@ -186,6 +183,9 @@ like they may have repeated the ``map`` control pattern. When we identify code
186183as a ``groupby `` operation we mentally collapse the detailed manipulation into
187184a single concept.
188185
186+ Additional Considerations
187+ ^^^^^^^^^^^^^^^^^^^^^^^^^
188+
189189The Toolz library contains dozens of patterns like ``map `` and ``groupby ``.
190190Learning a core set (maybe a dozen) covers the vast majority of common
191191programming tasks often done by hand.
0 commit comments