Commits

Mark Lavin committed be0fdf4

Lecture five not a minute too soon.

  • Participants
  • Parent commits c2708f6

Comments (0)

Files changed (9)

File code/closure.py

+def greater_than_bound(bound):
+    def greater(x):
+        return x > bound
+    return greater
+
+greater_than_ten = greater_than_bound(10)
+print greater_than_ten(20)
+

File code/identity.py

+def identity(n):
+    return [[1 if i == j else 0 for i in xrange(n)] for j in xrange(n)]
+
+print identity(3)
+
+print [(i, j) for i in xrange(3) for j in xrange(3)]

File code/iter.py

+from itertools import chain, takewhile, dropwhile
+from itertools import combinations, permutations
+
+a = [1, 2, 3]
+b = 'abc'
+print [(x, type(x)) for x in chain(a, b)]
+print [u''.join(x) for x in combinations(b, 2)]
+print [u''.join(x) for x in permutations(b, 2)]
+print list(takewhile(lambda x: x % 2 == 1, a))
+print list(dropwhile(lambda x: x in 'aeiou', b))

File code/keys.py

+from operator import itemgetter, attrgetter, methodcaller
+
+test = [(1, 2), (5, 3), (7, 1), (3, 8)]
+print sorted(test, key=itemgetter(1))
+
+test = ['C', 'a', 'd', 'B', 'E']
+print sorted(test, key=methodcaller('lower'))
+
+test = [1 +  1j, 2 - 1j, -1 + 2j]
+print sorted(test, key=attrgetter('real'))

File code/listsort.py

+test = ['C', 'a', 'd', 'B', 'E']
+test.sort()
+print test # Default alpha sort
+
+test.sort(key=str.lower)
+print test # Case insensitive alpha sort
+
+test = [(1, 2), (5, 3), (7, 1), (3, 8)]
+test.sort(key=lambda x: x[1])
+print test # Sort by second entry

File code/matrix.py

+text = '1,0,0;0,1,0;0,0,1'
+rows = text.split(';')
+matrix = []
+for row in rows:
+    matrix.append([float(x) for x in row.split(',')])
+print matrix
+
+matrix = map(lambda x: map(float, x.split(',')), text.split(';'))
+print matrix

File code/nightmare.py

+def simple(x, y=[]):
+    y.append(x)
+    return y
+
+print simple.func_defaults
+print simple(1)
+print simple(2)
+print simple.func_defaults

File lectures/five.rst

 Also it's fun.
 
 
-Anonymous Functions
+Some Notes on Function Parameters
 ----------------------------------------
 
-So far we have always defined functions using the ``def`` keyword. You can also
-define anonymous (unnamed) functions with ``lambda``.
+There was a mention about not passing an empty list as a default argument. This is
+not only true of lists but any mutable type such as a set or a dictionary.
 
-.. code-block:: python
+This is because the function defaults are evaluated when the function is defined. If
+the default type is mutable then it can be changed on subsequent function calls.
 
-    f = lambda x: x*x # Create a new function and assign to f
-    print f.__class__
-    print f(2)
+
+Function Nightmare (nightmare.py)
+----------------------------------------
+
+.. literalinclude:: /code/nightmare.py
 
 
 Getting Rid of Logical Blocks
         x_place = 'first'
     elif x == 2:
         x_place = 'second'
-    elif x == 3:
-        x_place = 'third'
     print x_place
-    print ((x == 1 and 'first') or (x == 2 and 'second') or
-        (x == 3 and 'third') or 'did not place')
+
+
+Short Circuit Example
+----------------------------------------
+
+.. code-block:: python
+
+    x = 2
+    print (x == 1 and 'first') or (x == 2 and 'second') or 'did not place'
+
+
+Using Short Circuit For Good
+----------------------------------------
+
+One of the best uses of this logical evaluation is handling default arguments
+that you want to be mutable types such as lists or dictionaries.
+
+.. code-block:: python
+
+    def simple(x=None):
+        x = x or {}
+        # Do some more work
 
 
 Getting Rid of Loops
     print [x for x in mix if isinstance(x, basestring)]
 
 
+Double List Comprehensions (identity.py)
+----------------------------------------
+
+You can have nested list comprehensions to eliminate nested for loops.
+
+.. literalinclude:: /code/identity.py
+
+
+Anonymous Functions
+----------------------------------------
+
+So far we have always defined functions using the ``def`` keyword. You can also
+define anonymous (unnamed) functions with ``lambda``.
+
+.. code-block:: python
+
+    f = lambda x: x*x # Create a new function and assign to f
+    print f.__class__
+    print f(2)
+
+
 More List Filtering
 ----------------------------------------
 
 Python 3.X.
 
 
+Map
+----------------------------------------
+
+``map`` applies a function to each item in an iterable and returns a list of the 
+results.
+
+.. code-block:: python
+
+    # Create list of the first four squares
+    squares = []
+    for x in [1, 2, 3, 4]:
+        squares.append(x**2)
+    # Becomes
+    squares = map(lambda x: x**2, [1, 2, 3, 4])
+
+
+Map Example (matrix.py)
+----------------------------------------
+
+.. literalinclude:: /code/matrix.py
+
+
 Sorting Lists
 ----------------------------------------
 
+The built-in list type has a ``sort`` method which sorts the list in place. ``sort`` can
+also take a ``key`` parameter which is a function which takes one parameter returns the value
+which will be used for the sorting. Passing ``reverse=True`` will reverse the sort order.
 
-Sorting List Example
+.. code-block:: python
+
+    test = [3, 4, 5, 1, 2]
+    test.sort()
+    print test
+    test = [3, 4, 5, 1, 2]
+    test.sort(key=lambda x: x % 3)
+    print test
+
+
+More List Sorting Examples (listsort.py)
 ----------------------------------------
 
+.. literalinclude:: /code/listsort.py
+
 
 Sorting Iterables
 ----------------------------------------
 
+``list.sort`` is great but what if you need to sort things that are iterables but not lists.
+For that you can use the built-in ``sorted`` function. The first argument is an iterable and
+the remaining arguments are the same as ``sort``. Unlike ``sort`` which returns ``None`` ``sorted``
+returns the sorted items as a list.
 
-Sorting Example
+.. code-block:: python
+
+    print sorted((8, 6, 7, 5, 3, 0, 9))
+    print sorted('jenny')
+    print sorted({'got': 'your number', 'need': 'make you mine'})
+
+
+Common Key Functions
 ----------------------------------------
 
+There are some common key functions:
 
-Map
+- Sorting a list of tuples (or nested list) by a given index
+- Sorting by an attribute
+- Sorting by a method
+
+While it isn't difficult to write these functions you can instead use the 
+``operator`` module.
+
+
+Key Functions Examples (keys.py)
 ----------------------------------------
 
-
-Map Example
-----------------------------------------
+.. literalinclude:: /code/keys.py
 
 
 ``itertools`` Module
 ----------------------------------------
 
+The ``itertools`` module defines functions for commonly used iterators.
 
-Getting Rid of Variables
+- Lists of integers
+- Cycles of sequences
+- Chains of iterators
+- Permutaions of a sequence
+- Combinations of a sequence
+
+
+``itertools`` Examples (iter.py)
 ----------------------------------------
 
-
-Debug This Mess
-----------------------------------------
+.. literalinclude:: /code/iter.py
 
 
 Closures
 ----------------------------------------
 
+Closures are combination of a function and an environment. They are named closures because
+they are said to "close over" free variables that are passed when defining the closure.
 
-``functools`` Module
+Since I'm sure none of that made any sense let's look at some examples.
+
+
+Closure Example (closure.py)
 ----------------------------------------
 
+.. literalinclude:: /code/closure.py
 
-Partial Functions
+
+Why Closures?
 ----------------------------------------
 
+Why in the world would you want to do this? Somethings are just too complicated for ``lambda``.
+``lambda`` expressions cannot contain ``if``, ``for`` or ``while`` statements. Though, as we have 
+seen, many of these statements can be replaced.
+
+
+Up Next
+----------------------------------------
+
+A tour of the Python standard library.
+
 
 .. header:: 
 

File slides/Spring2011/five.pdf

+%PDF-1.4
+%���� ReportLab Generated PDF document http://www.reportlab.com
+1 0 obj
+<< /F1 2 0 R
+ /F2 3 0 R
+ /F3 11 0 R
+ /F4 12 0 R
+ /F5 16 0 R >>
+endobj
+2 0 obj
+<< /BaseFont /Helvetica
+ /Encoding /WinAnsiEncoding
+ /Name /F1
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+3 0 obj
+<< /BaseFont /Helvetica-Bold
+ /Encoding /WinAnsiEncoding
+ /Name /F2
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+4 0 obj
+<< /Contents 68 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+5 0 obj
+<< /A << /S /URI
+ /Type /Action
+ /URI (http://en.wikipedia.org/wiki/Functional_programming) >>
+ /Border [ 0
+ 0
+ 0 ]
+ /Rect [ 73.57833
+ 191.1449
+ 110.9223
+ 203.1449 ]
+ /Subtype /Link
+ /Type /Annot >>
+endobj
+6 0 obj
+<< /Annots [ 5 0 R ]
+ /Contents 69 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+7 0 obj
+<< /Contents 70 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+8 0 obj
+<< /Contents 71 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+9 0 obj
+<< /Contents 72 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+10 0 obj
+<< /Contents 73 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+11 0 obj
+<< /BaseFont /Courier-Bold
+ /Encoding /WinAnsiEncoding
+ /Name /F3
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+12 0 obj
+<< /BaseFont /Courier
+ /Encoding /WinAnsiEncoding
+ /Name /F4
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+13 0 obj
+<< /Contents 74 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+14 0 obj
+<< /Contents 75 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+15 0 obj
+<< /Contents 76 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+16 0 obj
+<< /BaseFont /Courier-Oblique
+ /Encoding /WinAnsiEncoding
+ /Name /F5
+ /Subtype /Type1
+ /Type /Font >>
+endobj
+17 0 obj
+<< /Contents 77 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+18 0 obj
+<< /Contents 78 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+19 0 obj
+<< /Contents 79 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+20 0 obj
+<< /Contents 80 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+21 0 obj
+<< /Contents 81 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+22 0 obj
+<< /Contents 82 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+23 0 obj
+<< /Contents 83 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+24 0 obj
+<< /Contents 84 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+25 0 obj
+<< /Contents 85 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+26 0 obj
+<< /Contents 86 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+27 0 obj
+<< /Contents 87 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+28 0 obj
+<< /Contents 88 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+29 0 obj
+<< /Contents 89 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+30 0 obj
+<< /Contents 90 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+31 0 obj
+<< /Contents 91 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+32 0 obj
+<< /Contents 92 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+33 0 obj
+<< /Contents 93 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+34 0 obj
+<< /Contents 94 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+35 0 obj
+<< /Contents 95 0 R
+ /MediaBox [ 0
+ 0
+ 453.5433
+ 255.1181 ]
+ /Parent 67 0 R
+ /Resources << /Font 1 0 R
+ /ProcSet [ /PDF
+ /Text
+ /ImageB
+ /ImageC
+ /ImageI ] >>
+ /Rotate 0
+ /Trans <<  >>
+ /Type /Page >>
+endobj
+36 0 obj
+<< /Outlines 38 0 R
+ /PageLabels 96 0 R
+ /PageMode /UseNone
+ /Pages 67 0 R
+ /Type /Catalog >>
+endobj
+37 0 obj
+<< /Author ()
+ /CreationDate (D:20000101000000+00'00')
+ /Creator (\(unspecified\))
+ /Keywords ()
+ /Producer (ReportLab PDF Library - www.reportlab.com)
+ /Subject (\(unspecified\))
+ /Title () >>
+endobj
+38 0 obj
+<< /Count 28
+ /First 39 0 R
+ /Last 66 0 R
+ /Type /Outlines >>
+endobj
+39 0 obj
+<< /Dest [ 4 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 40 0 R
+ /Parent 38 0 R
+ /Title (Functional Tools in Python) >>
+endobj
+40 0 obj
+<< /Dest [ 6 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 41 0 R
+ /Parent 38 0 R
+ /Prev 39 0 R
+ /Title (What is Functional Programming?) >>
+endobj
+41 0 obj
+<< /Dest [ 7 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 42 0 R
+ /Parent 38 0 R
+ /Prev 40 0 R
+ /Title (What are Some Functional Languages?) >>
+endobj
+42 0 obj
+<< /Dest [ 8 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 43 0 R
+ /Parent 38 0 R
+ /Prev 41 0 R
+ /Title (Disclaimer) >>
+endobj
+43 0 obj
+<< /Dest [ 9 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 44 0 R
+ /Parent 38 0 R
+ /Prev 42 0 R
+ /Title (Who Cares?) >>
+endobj
+44 0 obj
+<< /Dest [ 10 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 45 0 R
+ /Parent 38 0 R
+ /Prev 43 0 R
+ /Title (Some Notes on Function Parameters) >>
+endobj
+45 0 obj
+<< /Dest [ 13 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 46 0 R
+ /Parent 38 0 R
+ /Prev 44 0 R
+ /Title (Function Nightmare \(nightmare.py\)) >>
+endobj
+46 0 obj
+<< /Dest [ 14 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 47 0 R
+ /Parent 38 0 R
+ /Prev 45 0 R
+ /Title (Getting Rid of Logical Blocks) >>
+endobj
+47 0 obj
+<< /Dest [ 15 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 48 0 R
+ /Parent 38 0 R
+ /Prev 46 0 R
+ /Title (Short Circuit Example) >>
+endobj
+48 0 obj
+<< /Dest [ 17 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 49 0 R
+ /Parent 38 0 R
+ /Prev 47 0 R
+ /Title (Using Short Circuit For Good) >>
+endobj
+49 0 obj
+<< /Dest [ 18 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 50 0 R
+ /Parent 38 0 R
+ /Prev 48 0 R
+ /Title (Getting Rid of Loops) >>
+endobj
+50 0 obj
+<< /Dest [ 19 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 51 0 R
+ /Parent 38 0 R
+ /Prev 49 0 R
+ /Title (Double List Comprehensions \(identity.py\)) >>
+endobj
+51 0 obj
+<< /Dest [ 20 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 52 0 R
+ /Parent 38 0 R
+ /Prev 50 0 R
+ /Title (Anonymous Functions) >>
+endobj
+52 0 obj
+<< /Dest [ 21 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 53 0 R
+ /Parent 38 0 R
+ /Prev 51 0 R
+ /Title (More List Filtering) >>
+endobj
+53 0 obj
+<< /Dest [ 22 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 54 0 R
+ /Parent 38 0 R
+ /Prev 52 0 R
+ /Title (Getting Rid of More Loops) >>
+endobj
+54 0 obj
+<< /Dest [ 23 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 55 0 R
+ /Parent 38 0 R
+ /Prev 53 0 R
+ /Title (Map) >>
+endobj
+55 0 obj
+<< /Dest [ 24 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 56 0 R
+ /Parent 38 0 R
+ /Prev 54 0 R
+ /Title (Map Example \(matrix.py\)) >>
+endobj
+56 0 obj
+<< /Dest [ 25 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 57 0 R
+ /Parent 38 0 R
+ /Prev 55 0 R
+ /Title (Sorting Lists) >>
+endobj
+57 0 obj
+<< /Dest [ 26 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 58 0 R
+ /Parent 38 0 R
+ /Prev 56 0 R
+ /Title (More List Sorting Examples \(listsort.py\)) >>
+endobj
+58 0 obj
+<< /Dest [ 27 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 59 0 R
+ /Parent 38 0 R
+ /Prev 57 0 R
+ /Title (Sorting Iterables) >>
+endobj
+59 0 obj
+<< /Dest [ 28 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 60 0 R
+ /Parent 38 0 R
+ /Prev 58 0 R
+ /Title (Common Key Functions) >>
+endobj
+60 0 obj
+<< /Dest [ 29 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 61 0 R
+ /Parent 38 0 R
+ /Prev 59 0 R
+ /Title (Key Functions Examples \(keys.py\)) >>
+endobj
+61 0 obj
+<< /Dest [ 30 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 62 0 R
+ /Parent 38 0 R
+ /Prev 60 0 R
+ /Title (itertools Module) >>
+endobj
+62 0 obj
+<< /Dest [ 31 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 63 0 R
+ /Parent 38 0 R
+ /Prev 61 0 R
+ /Title (itertools Examples \(iter.py\)) >>
+endobj
+63 0 obj
+<< /Dest [ 32 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 64 0 R
+ /Parent 38 0 R
+ /Prev 62 0 R
+ /Title (Closures) >>
+endobj
+64 0 obj
+<< /Dest [ 33 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 65 0 R
+ /Parent 38 0 R
+ /Prev 63 0 R
+ /Title (Closure Example \(closure.py\)) >>
+endobj
+65 0 obj
+<< /Dest [ 34 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Next 66 0 R
+ /Parent 38 0 R
+ /Prev 64 0 R
+ /Title (Why Closures?) >>
+endobj
+66 0 obj
+<< /Dest [ 35 0 R
+ /XYZ
+ 51.35433
+ 222.9449
+ 0 ]
+ /Parent 38 0 R
+ /Prev 65 0 R
+ /Title (Up Next) >>
+endobj
+67 0 obj
+<< /Count 28
+ /Kids [ 4 0 R
+ 6 0 R
+ 7 0 R
+ 8 0 R
+ 9 0 R
+ 10 0 R
+ 13 0 R
+ 14 0 R
+ 15 0 R
+ 17 0 R
+ 18 0 R
+ 19 0 R
+ 20 0 R
+ 21 0 R
+ 22 0 R
+ 23 0 R
+ 24 0 R
+ 25 0 R
+ 26 0 R
+ 27 0 R
+ 28 0 R
+ 29 0 R
+ 30 0 R
+ 31 0 R
+ 32 0 R
+ 33 0 R
+ 34 0 R
+ 35 0 R ]
+ /Type /Pages >>
+endobj
+68 0 obj
+<< /Length 644 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Functional Tools in Python) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (A brief introduction to Functional Programming in Python.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+69 0 obj
+<< /Length 1186 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (What is Functional Programming?) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+BT 1 0 0 1 0 4 Tm 12 TL /F2 8 Tf 0 0 0 rg (From ) Tj 0 0 .501961 rg (Wikipedia) Tj 0 0 0 rg (::) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 137.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+BT 1 0 0 1 0 38 Tm  T* ET
+q
+1 0 0 1 20 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 40 Tm /F1 8 Tf 12 TL 3.071465 Tw (...Functional programming is a programming paradigm that treats computation as the) Tj T* 0 Tw .814887 Tw (evaluation of mathematical functions and avoids state and mutable data. It emphasizes the) Tj T* 0 Tw .811877 Tw (application of functions, in contrast to the imperative programming style, which emphasizes) Tj T* 0 Tw (changes in state.) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 137.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+70 0 obj
+<< /Length 2892 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (What are Some Functional Languages?) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Popular functional programming languages:) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Scheme) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+Q
+q
+1 0 0 1 51.35433 164.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Erlang) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 164.1449 cm
+Q
+q
+1 0 0 1 51.35433 152.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (OCaml) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 152.1449 cm
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Haskell) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+Q
+q
+1 0 0 1 51.35433 128.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (F#) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 128.1449 cm
+Q
+q
+1 0 0 1 51.35433 116.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Clojure) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 116.1449 cm
+Q
+q
+1 0 0 1 51.35433 104.1449 cm
+0 0 0 rg
+BT /F1 10 Tf 12 TL ET
+q
+1 0 0 1 6 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 11.2 0 Td (\177) Tj T* -11.2 0 Td ET
+Q
+Q
+q
+1 0 0 1 23 -3 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (R) Tj T* ET
+Q
+Q
+q
+Q
+Q
+q
+1 0 0 1 51.35433 104.1449 cm
+Q
+q
+1 0 0 1 51.35433 104.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+71 0 obj
+<< /Length 1483 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Disclaimer) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 140.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 52 Tm /F1 8 Tf 12 TL 1.638455 Tw (I do not claim to be a master of functional programming nor is this meant to be a lesson on) Tj T* 0 Tw 1.056665 Tw (functional programming. This is meant to be a look into Python features which are related to or) Tj T* 0 Tw .780887 Tw (insipred by functional programming. While these concepts are handy for all Python programmers) Tj T* 0 Tw 1.334273 Tw (and will carry into other functional languages, this is not meant to imply that Python is a great) Tj T* 0 Tw (functional language.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 98.14488 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 28 Tm /F1 8 Tf 12 TL .370843 Tw (You'll notice Python is not listed as a popular functional langages. Python has functional tools and) Tj T* 0 Tw .694165 Tw (idioms but is not a purely functional language. If you find think interesting I suggest you consider) Tj T* 0 Tw (looking into one of the previously listed functional languages.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 98.14488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+72 0 obj
+<< /Length 1325 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Who Cares?) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 152.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 40 Tm /F1 8 Tf 12 TL 1.243376 Tw (Testing and debugging functional programs tend to be easier. There is no global state and the) Tj T* 0 Tw .445332 Tw (program is a sequence of function calls. Functions tend to be small and compartmentalized. Each) Tj T* 0 Tw 1.67405 Tw (function can be tested individually. Debugging involves checking the input and output of each) Tj T* 0 Tw (function call.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 122.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL .24315 Tw (Functional programming/languages have been growing in popularity in industry and knowing these) Tj T* 0 Tw (languages/concepts makes for a rare marketable skill.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 104.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (Also it's fun.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 104.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+73 0 obj
+<< /Length 1064 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Some Notes on Function Parameters) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL .070034 Tw (There was a mention about not passing an empty list as a default argument. This is not only true of) Tj T* 0 Tw (lists but any mutable type such as a set or a dictionary.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 146.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL .220165 Tw (This is because the function defaults are evaluated when the function is defined. If the default type) Tj T* 0 Tw (is mutable then it can be changed on subsequent function calls.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 146.1449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+74 0 obj
+<< /Length 1525 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Function Nightmare \(nightmare.py\)) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 88.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 108 re B*
+Q
+q
+BT 1 0 0 1 0 88 Tm 12 TL /F3 8 Tf 0 .501961 0 rg (def) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 0 1 rg (simple) Tj 0 0 0 rg (\() Tj (x) Tj (,) Tj ( ) Tj (y) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ([]\):) Tj  T* (    ) Tj (y) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (append) Tj (\() Tj (x) Tj (\)) Tj  T* (    ) Tj /F3 8 Tf 0 .501961 0 rg (return) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (y) Tj  T*  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (simple) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (func_defaults) Tj  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (simple) Tj (\() Tj .4 .4 .4 rg (1) Tj 0 0 0 rg (\)) Tj  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (simple) Tj (\() Tj .4 .4 .4 rg (2) Tj 0 0 0 rg (\)) Tj  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (simple) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (func_defaults) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 80.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+75 0 obj
+<< /Length 1744 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Getting Rid of Logical Blocks) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL 2.352189 Tw (Small logical blocks can often be removed by making use of Python short circuiting logical) Tj T* 0 Tw (statements.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 70.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 96 re B*
+Q
+q
+BT 1 0 0 1 0 76 Tm 12 TL /F4 8 Tf 0 0 0 rg (x) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg  T* (x_place) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ('did not place') Tj 0 0 0 rg  T* /F3 8 Tf 0 .501961 0 rg (if) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj ( ) Tj .4 .4 .4 rg (==) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (1) Tj 0 0 0 rg (:) Tj  T* (    ) Tj (x_place) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ('first') Tj 0 0 0 rg  T* /F3 8 Tf 0 .501961 0 rg (elif) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj ( ) Tj .4 .4 .4 rg (==) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg (:) Tj  T* (    ) Tj (x_place) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ('second') Tj 0 0 0 rg  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x_place) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 62.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+76 0 obj
+<< /Length 1467 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Short Circuit Example) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 160.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 36 re B*
+Q
+q
+BT 1 0 0 1 0 16 Tm 12 TL /F4 8 Tf 0 0 0 rg (x) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (\() Tj (x) Tj ( ) Tj .4 .4 .4 rg (==) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (1) Tj 0 0 0 rg ( ) Tj /F3 8 Tf .666667 .133333 1 rg (and) Tj /F4 8 Tf 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ('first') Tj 0 0 0 rg (\)) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (or) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (\() Tj (x) Tj ( ) Tj .4 .4 .4 rg (==) Tj 0 0 0 rg ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg ( ) Tj /F3 8 Tf .666667 .133333 1 rg (and) Tj /F4 8 Tf 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ('second') Tj 0 0 0 rg (\)) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (or) Tj /F4 8 Tf 0 0 0 rg ( ) Tj .729412 .129412 .129412 rg ('did not place') Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 152.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+77 0 obj
+<< /Length 1350 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Using Short Circuit For Good) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL .783214 Tw (One of the best uses of this logical evaluation is handling default arguments that you want to be) Tj T* 0 Tw (mutable types such as lists or dictionaries.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 118.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 48 re B*
+Q
+q
+BT 1 0 0 1 0 28 Tm 12 TL /F3 8 Tf 0 .501961 0 rg (def) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 0 1 rg (simple) Tj 0 0 0 rg (\() Tj (x) Tj .4 .4 .4 rg (=) Tj 0 .501961 0 rg (None) Tj 0 0 0 rg (\):) Tj  T* (    ) Tj (x) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj (x) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (or) Tj /F4 8 Tf 0 0 0 rg ( ) Tj ({}) Tj  T* (    ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Do some more work) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 110.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+78 0 obj
+<< /Length 2304 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Getting Rid of Loops) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 16 Tm /F1 8 Tf 12 TL 1.632176 Tw (List comprehensions allow you to build loops in place. Simple loops can be removed with list) Tj T* 0 Tw (comprehensions. The Python 3.X series supports dictionary and set comprehensions as well.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 70.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 96 re B*
+Q
+q
+BT 1 0 0 1 0 76 Tm 12 TL /F4 8 Tf 0 0 0 rg (mix) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj ([) Tj .4 .4 .4 rg (1) Tj 0 0 0 rg (,) Tj ( ) Tj .729412 .129412 .129412 rg ('a') Tj 0 0 0 rg (,) Tj ( ) Tj .729412 .129412 .129412 rg ('b') Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (4) Tj 0 0 0 rg (]) Tj  T* (letters) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj ([]) Tj  T* /F3 8 Tf 0 .501961 0 rg (for) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (in) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (mix) Tj (:) Tj  T* (    ) Tj /F3 8 Tf 0 .501961 0 rg (if) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (isinstance) Tj 0 0 0 rg (\() Tj (mix) Tj (,) Tj ( ) Tj 0 .501961 0 rg (basestring) Tj 0 0 0 rg (\):) Tj  T* (        ) Tj (letters) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (append) Tj (\() Tj (x) Tj (\)) Tj  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (letters) Tj  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj ([) Tj (x) Tj ( ) Tj /F3 8 Tf 0 .501961 0 rg (for) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (in) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (mix) Tj ( ) Tj /F3 8 Tf 0 .501961 0 rg (if) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (isinstance) Tj 0 0 0 rg (\() Tj (x) Tj (,) Tj ( ) Tj 0 .501961 0 rg (basestring) Tj 0 0 0 rg (\)]) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 62.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+79 0 obj
+<< /Length 2405 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Double List Comprehensions \(identity.py\)) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL (You can have nested list comprehensions to eliminate nested for loops.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 94.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 352.8 84 re B*
+Q
+q
+BT 1 0 0 1 0 64 Tm 12 TL /F3 8 Tf 0 .501961 0 rg (def) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 0 1 rg (identity) Tj 0 0 0 rg (\() Tj (n) Tj (\):) Tj  T* (    ) Tj /F3 8 Tf 0 .501961 0 rg (return) Tj /F4 8 Tf 0 0 0 rg ( ) Tj ([[) Tj .4 .4 .4 rg (1) Tj 0 0 0 rg ( ) Tj /F3 8 Tf 0 .501961 0 rg (if) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (i) Tj ( ) Tj .4 .4 .4 rg (==) Tj 0 0 0 rg ( ) Tj (j) Tj ( ) Tj /F3 8 Tf 0 .501961 0 rg (else) Tj /F4 8 Tf 0 0 0 rg ( ) Tj .4 .4 .4 rg (0) Tj 0 0 0 rg ( ) Tj /F3 8 Tf 0 .501961 0 rg (for) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (i) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (in) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (xrange) Tj 0 0 0 rg (\() Tj (n) Tj (\)]) Tj ( ) Tj /F3 8 Tf 0 .501961 0 rg (for) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (j) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (in) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (xrange) Tj 0 0 0 rg (\() Tj (n) Tj (\)]) Tj  T*  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (identity) Tj (\() Tj .4 .4 .4 rg (3) Tj 0 0 0 rg (\)) Tj  T*  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj ([\() Tj (i) Tj (,) Tj ( ) Tj (j) Tj (\)) Tj ( ) Tj /F3 8 Tf 0 .501961 0 rg (for) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (i) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (in) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (xrange) Tj 0 0 0 rg (\() Tj .4 .4 .4 rg (3) Tj 0 0 0 rg (\)) Tj ( ) Tj /F3 8 Tf 0 .501961 0 rg (for) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (j) Tj ( ) Tj /F3 8 Tf .666667 .133333 1 rg (in) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (xrange) Tj 0 0 0 rg (\() Tj .4 .4 .4 rg (3) Tj 0 0 0 rg (\)]) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 86.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+80 0 obj
+<< /Length 1523 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Anonymous Functions) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+BT 1 0 0 1 0 16 Tm .260976 Tw 12 TL /F1 8 Tf 0 0 0 rg (So far we have always defined functions using the ) Tj /F4 8 Tf (def ) Tj /F1 8 Tf (keyword. You can also define anonymous) Tj T* 0 Tw (\(unnamed\) functions with ) Tj /F4 8 Tf (lambda) Tj /F1 8 Tf (.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 118.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 48 re B*
+Q
+q
+BT 1 0 0 1 0 28 Tm 12 TL /F4 8 Tf 0 0 0 rg (f) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj /F3 8 Tf 0 .501961 0 rg (lambda) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj (:) Tj ( ) Tj (x) Tj .4 .4 .4 rg (*) Tj 0 0 0 rg (x) Tj ( ) Tj /F5 8 Tf .25098 .501961 .501961 rg (# Create a new function and assign to f) Tj /F4 8 Tf 0 0 0 rg  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (f) Tj .4 .4 .4 rg (.) Tj 0 0 0 rg (__class__) Tj  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (f) Tj (\() Tj .4 .4 .4 rg (2) Tj 0 0 0 rg (\)) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 110.9449 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+81 0 obj
+<< /Length 1798 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (More List Filtering) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 164.1449 cm
+q
+BT 1 0 0 1 0 28 Tm 1.57945 Tw 12 TL /F1 8 Tf 0 0 0 rg (You can also use the ) Tj /F4 8 Tf (filter ) Tj /F1 8 Tf (function. The first argument is the function to be used for the) Tj T* 0 Tw 1.389165 Tw (filtering. This could be a defined function or a lambda. The second argument is the iterable. It) Tj T* 0 Tw (returns the filtered list.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 106.9449 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 48 re B*
+Q
+q
+BT 1 0 0 1 0 28 Tm 12 TL /F4 8 Tf 0 0 0 rg (mix) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj ([) Tj .4 .4 .4 rg (1) Tj 0 0 0 rg (,) Tj ( ) Tj .729412 .129412 .129412 rg ('a') Tj 0 0 0 rg (,) Tj ( ) Tj .729412 .129412 .129412 rg ('b') Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (4) Tj 0 0 0 rg (]) Tj  T* (letters) Tj ( ) Tj .4 .4 .4 rg (=) Tj 0 0 0 rg ( ) Tj 0 .501961 0 rg (filter) Tj 0 0 0 rg (\() Tj /F3 8 Tf 0 .501961 0 rg (lambda) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj (:) Tj ( ) Tj 0 .501961 0 rg (isinstance) Tj 0 0 0 rg (\() Tj (x) Tj (,) Tj ( ) Tj 0 .501961 0 rg (basestring) Tj 0 0 0 rg (\),) Tj ( ) Tj (mix) Tj (\)) Tj  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (letters) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 98.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+82 0 obj
+<< /Length 2495 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Getting Rid of More Loops) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 176.1449 cm
+q
+BT 1 0 0 1 0 16 Tm 1.390165 Tw 12 TL /F1 8 Tf 0 0 0 rg (List filtering isn't the only type of lists you can remove. The ) Tj /F4 8 Tf (reduce ) Tj /F1 8 Tf (function applies a binary) Tj T* 0 Tw (function in sequence to an iterable.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 158.1449 cm
+q
+BT 1 0 0 1 0 4 Tm 12 TL /F1 8 Tf 0 0 0 rg (Here is a simple total using ) Tj /F4 8 Tf (reduce) Tj /F1 8 Tf (.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 88.94488 cm
+q
+q
+q
+1 0 0 1 6.6 6.6 cm
+q
+.662745 .662745 .662745 RG
+.5 w
+.960784 .960784 .862745 rg
+n -6 -6 349.6346 60 re B*
+Q
+q
+BT 1 0 0 1 0 40 Tm 12 TL /F5 8 Tf .25098 .501961 .501961 rg (# This is equivalent to \(\(1 + 2\) + 3\) + 4\)) Tj /F4 8 Tf 0 0 0 rg  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (reduce) Tj 0 0 0 rg (\() Tj /F3 8 Tf 0 .501961 0 rg (lambda) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj (,) Tj ( ) Tj (y) Tj (:) Tj ( ) Tj (x) Tj ( ) Tj .4 .4 .4 rg (+) Tj 0 0 0 rg ( ) Tj (y) Tj (,) Tj ( ) Tj ([) Tj .4 .4 .4 rg (1) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (3) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (4) Tj 0 0 0 rg (]\)) Tj  T* /F5 8 Tf .25098 .501961 .501961 rg (# This is equivalent to \(\(1 * 2\) * 3\) * 4\) or 4!) Tj /F4 8 Tf 0 0 0 rg  T* /F3 8 Tf 0 .501961 0 rg (print) Tj /F4 8 Tf 0 0 0 rg ( ) Tj 0 .501961 0 rg (reduce) Tj 0 0 0 rg (\() Tj /F3 8 Tf 0 .501961 0 rg (lambda) Tj /F4 8 Tf 0 0 0 rg ( ) Tj (x) Tj (,) Tj ( ) Tj (y) Tj (:) Tj ( ) Tj (x) Tj ( ) Tj .4 .4 .4 rg (*) Tj 0 0 0 rg ( ) Tj (y) Tj (,) Tj ( ) Tj ([) Tj .4 .4 .4 rg (1) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (2) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (3) Tj 0 0 0 rg (,) Tj ( ) Tj .4 .4 .4 rg (4) Tj 0 0 0 rg (]\)) Tj T* ET
+Q
+Q
+Q
+Q
+Q
+q
+1 0 0 1 51.35433 68.94488 cm
+q
+BT 1 0 0 1 0 4 Tm 12 TL /F4 8 Tf 0 0 0 rg (reduce ) Tj /F1 8 Tf (is built-in to Python 2.X but was moved to the ) Tj /F4 8 Tf (functools ) Tj /F1 8 Tf (module in Python 3.X.) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 68.94488 cm
+Q
+q
+1 0 0 1 0 243.1181 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 170.9637 0 Td (MA792K Spring 2011 Lecture 5) Tj T* -170.9637 0 Td ET
+Q
+Q
+q
+1 0 0 1 0 0 cm
+q
+0 0 0 rg
+BT 1 0 0 1 0 4 Tm /F1 8 Tf 12 TL 193.1437 0 Td (\251 Mark Lavin 2011) Tj T* -193.1437 0 Td ET
+Q
+Q
+ 
+endstream
+endobj
+83 0 obj
+<< /Length 1950 >>
+stream
+1 0 0 1 0 0 cm  BT /F1 12 Tf 14.4 TL ET
+q
+1 0 0 1 51.35433 206.1449 cm
+q
+BT 1 0 0 1 0 2.8 Tm 16.8 TL /F2 14 Tf 0 0 0 rg (Map) Tj T* ET
+Q
+Q
+q
+1 0 0 1 51.35433 188.1449 cm