{ "metadata": { "name": "", "signature": "sha256:974ed696dcf628ef7f619b1d6f79504fddd41a0ff09c1a485ec5203f4dd8be00" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lambda Functions\n", "\n", "- **Author:** [Chris Albon](http://www.chrisalbon.com/), [@ChrisAlbon](https://twitter.com/chrisalbon)\n", "- **Date:** -\n", "- **Repo:** [Python 3 code snippets for data science](https://github.com/chrisalbon/code_py)\n", "- **Note:** From: Learning Python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Lambda functions can act as mini-functions, allowing you to create small bits of code into things like series." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create a series, called pipeline, that contains three mini functions" ] }, { "cell_type": "code", "collapsed": true, "input": [ "pipeline = [lambda x: x **2 - 1 + 5,\n", " lambda x: x **20 - 2 + 3,\n", " lambda x: x **200 - 1 + 4]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### For each item in pipeline, run the lambda function with x = 3" ] }, { "cell_type": "code", "collapsed": false, "input": [ "for f in pipeline:\n", " print(f(3))" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }