Skip to content
Snippets Groups Projects
Commit d8151811 authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

a few little fixes we noticed today in class if you choose to make them :)

parent acd93a0f
No related branches found
No related tags found
1 merge request!8a few little fixes we noticed today in class if you choose to make them :)
...@@ -180,7 +180,7 @@ list(map(add3, [1, 5, 3, 1, 6])) ...@@ -180,7 +180,7 @@ list(map(add3, [1, 5, 3, 1, 6]))
\item Write a function \texttt{repit(xs)} that takes a list \texttt{xs} and produces a new list \item Write a function \texttt{repit(xs)} that takes a list \texttt{xs} and produces a new list
that replicates each entry 3 times that replicates each entry 3 times
\bi \bi
\item \texttt{[1, 2, 3]} $\rightarrow$ \texttt{[1, 1, 1], [2, 2, 2], [3, 3, 3]} \item \texttt{[1, 2, 3]} $\rightarrow$ \texttt{[[1, 1, 1], [2, 2, 2], [3, 3, 3]]}
\item $\mbox{map}: (a \rightarrow b) \times [a] \rightarrow [b]$ \item $\mbox{map}: (a \rightarrow b) \times [a] \rightarrow [b]$
\item $\mbox{map}: (t \rightarrow [t]) \times [t] \rightarrow [[t]]$ \item $\mbox{map}: (t \rightarrow [t]) \times [t] \rightarrow [[t]]$
\item $\mbox{rep}: t \times int \rightarrow [t]$ \item $\mbox{rep}: t \times int \rightarrow [t]$
...@@ -306,7 +306,7 @@ def even(x): ...@@ -306,7 +306,7 @@ def even(x):
\item \texttt{accum} is the initial value for the accumulator \item \texttt{accum} is the initial value for the accumulator
\item In Python 3 need \texttt{from functools import reduce} \item In Python 3 need \texttt{from functools import reduce}
\item \structure{How would you use reduce to calculate the sum of the numbers \item \structure{How would you use reduce to calculate the sum of the numbers
from 1 to 100?} from 1 to 5?}
\item \structure{How about the product?} \item \structure{How about the product?}
\ei \ei
\end{frame} \end{frame}
...@@ -317,7 +317,7 @@ def even(x): ...@@ -317,7 +317,7 @@ def even(x):
\frametitle{Understanding Reduce for Sum} \frametitle{Understanding Reduce for Sum}
\bi \bi
\item \texttt{reduce(lambda x, y: x+y, range(1, 5), 0)} \item \texttt{reduce(lambda x, y: x+y, range(1, 6), 0)}
\item \texttt{reduce(lambda x, y: x+y, [1, 2, 3, 4, 5], 0)} \item \texttt{reduce(lambda x, y: x+y, [1, 2, 3, 4, 5], 0)}
\item \texttt{((((0+1)+2)+3)+4)+5} \item \texttt{((((0+1)+2)+3)+4)+5}
\ei \ei
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment