Skip to content

Instantly share code, notes, and snippets.

@johnchristopher
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnchristopher/d69a85a539634d4961e3 to your computer and use it in GitHub Desktop.
Save johnchristopher/d69a85a539634d4961e3 to your computer and use it in GitHub Desktop.
{"nbformat_minor": 0, "cells": [{"execution_count": 2, "cell_type": "code", "source": "s='12'", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 3, "cell_type": "code", "source": "map(int, s)", "outputs": [{"execution_count": 3, "output_type": "execute_result", "data": {"text/plain": "[1, 2]"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Note que `int` est invoqu\u00e9 sans les parenth\u00e8ses.", "cell_type": "markdown", "metadata": {}}, {"execution_count": 4, "cell_type": "code", "source": "[int(x) for x in s]", "outputs": [{"execution_count": 4, "output_type": "execute_result", "data": {"text/plain": "[1, 2]"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "List comprehension. C'est d\u00e9j\u00e0 plus _pythonic_ comme ils disent.", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "filter(lambda l: l == '1', s)", "outputs": [{"execution_count": 14, "output_type": "execute_result", "data": {"text/plain": "'1'"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 13, "cell_type": "code", "source": "[x for x in s if x == '1']", "outputs": [{"execution_count": 13, "output_type": "execute_result", "data": {"text/plain": "['1']"}, "metadata": {}}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "Note que `filter` (du tryptique map/reduce/filter) ne retourne pas une liste :(.", "cell_type": "markdown", "metadata": {}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment