Added lambda snippet.

This commit is contained in:
Donne Martin 2015-01-26 15:43:27 -05:00
parent 4f79034549
commit 9e87f05f43

View File

@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:93f08d982c73b7b50d2c679984dc25a00cc198f32a1a82269c2c119da5d0e26e"
"signature": "sha256:a37a234cd37895919493dabe7ab645bb2b5e24d9b304ab564e18b59eac4f7a0a"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -20,7 +20,7 @@
"metadata": {},
"source": [
"* Functions as Objects\n",
"* Lambdas\n",
"* Lambda Functions\n",
"* Closures\n",
"* \\*args, \\*\\*kwargs\n",
"* Currying\n",
@ -157,6 +157,49 @@
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lambda Functions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lambda functions are anonymous function and are convenient for data analysis, as data transformation functions take functions as arguments."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Sort a sequence of strings by the number of letters"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"strings = ['foo', 'bar,', 'baz', 'f', 'fo', 'b', 'ba']\n",
"strings.sort(key=lambda x: len(list(x)))\n",
"strings"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"text": [
"['f', 'b', 'fo', 'ba', 'foo', 'baz', 'bar,']"
]
}
],
"prompt_number": 7
}
],
"metadata": {}