Skip to content

Commit

Permalink
fixed example in 4c
Browse files Browse the repository at this point in the history
  • Loading branch information
joncbates committed Jun 30, 2015
1 parent c2deecd commit 8b6d1b1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ML_lab1_review_student.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"labVersion = 'cs190_week1_v_1_1'"
"labVersion = 'cs190_week1_v_1_2'"
]
},
{
Expand Down Expand Up @@ -652,7 +652,7 @@
"source": [
"#### ** (4c) Lambda expression arguments **\n",
"#### Lambda expressions can be used to generate functions that take in zero or more parameters. The syntax for `lambda` allows for multiple ways to define the same function. For example, we might want to create a function that takes in a single parameter, where the parameter is a tuple consisting of two values, and the function adds the two values together. The syntax could be either: `lambda x: x[0] + x[1]` or `lambda (x0, x1): x0 + x1`. If we called either function on the tuple `(3, 4)` it would return `7`. Note that the second `lambda` relies on the tuple `(3, 4)` being unpacked automatically, which means that `x0` is assigned the value `3` and `x1` is assigned the value `4`.\n",
"#### As an other example, consider the following parameter lambda expressions: `lambda x, y: (x[0] + y[0], x[1] + y[1])` and `lambda (x0, x1), (y0, y1): (x0 + x1, y0 + y1)`. The result of applying either of these functions to tuples `(1, 2)` and `(3, 4)` would be the tuple `(4, 6)`.\n",
"#### As an other example, consider the following parameter lambda expressions: `lambda x, y: (x[0] + y[0], x[1] + y[1])` and `lambda (x0, x1), (y0, y1): (x0 + y0, x1 + y1)`. The result of applying either of these functions to tuples `(1, 2)` and `(3, 4)` would be the tuple `(4, 6)`.\n",
"#### For this exercise: you'll create one-parameter functions `swap1` and `swap2` that swap the order of a tuple; a one-parameter function `swapOrder` that takes in a tuple with three values and changes the order to: second element, third element, first element; and finally, a three-parameter function `sumThree` that takes in three tuples, each with two values, and returns a tuple containing two values: the sum of the first element of each tuple and the sum of second element of each tuple."
]
},
Expand All @@ -674,9 +674,9 @@
"\n",
"# Two-parameter function\n",
"b1 = lambda x, y: (x[0] + y[0], x[1] + y[1])\n",
"b2 = lambda (x0, x1), (y0, y1): (x0 + x1, y0 + y1)\n",
"b2 = lambda (x0, x1), (y0, y1): (x0 + y0, x1 + y1)\n",
"print '\\nb1( (1,2), (3,4) ) = {0}'.format( b1( (1,2), (3,4) ) )\n",
"print 'b2( (1,2), (3,4) ) = {0}'.format( b1( (1,2), (3,4) ) )"
"print 'b2( (1,2), (3,4) ) = {0}'.format( b2( (1,2), (3,4) ) )"
]
},
{
Expand Down

0 comments on commit 8b6d1b1

Please sign in to comment.