From edf3519032edfc58cf6885c1ca2e8ca0ba6e8a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Mon, 24 Feb 2014 03:40:29 -0800 Subject: [PATCH] --- array_combination.ipynb | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/array_combination.ipynb b/array_combination.ipynb index 33c6634..6f2d4c0 100644 --- a/array_combination.ipynb +++ b/array_combination.ipynb @@ -10,11 +10,11 @@ { "cell_type": "code", "collapsed": false, - "input": "a=set([1,2,3,4])\nb=set([4,5,6,7])\nc=set([7,8,9])", + "input": "a=set([3,4])\nb=set([3,7])", "language": "python", "metadata": {}, "outputs": [], - "prompt_number": 5 + "prompt_number": 112 }, { "cell_type": "code", @@ -28,37 +28,26 @@ { "cell_type": "code", "collapsed": false, - "input": "def shuffle(*args):\n combinations = [[i] for i in args[0]]\n for arg in args[1:]:\n tempcomb = []\n for i in arg:\n print i\n tempcomb += [c+[i] for c in combinations if i not in c ]\n combinations = tempcomb\n return combinations\nshuffle(a,b,c)", + "input": "def array_combinations(*args):\n combinations = [[i] for i in set(args[0])]\n for arg in args[1:]:\n tempcomb = []\n for i in set(arg):\n tempcomb += [c+[i] for c in combinations if i not in c ]\n combinations = tempcomb\n return combinations\nres = array_combinations(a,b)\nprint res\nprint len(res)", "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "4\n5\n6\n7\n8\n9\n7\n" + "text": "[[4, 3], [3, 7], [4, 7]]\n3\n" } ], - "prompt_number": 50 + "prompt_number": 115 }, { "cell_type": "code", "collapsed": false, - "input": "x= [2,4,3]\nx + 6", + "input": "", "language": "python", "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "can only concatenate list (not \"int\") to list", - "output_type": "pyerr", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mx\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m6\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m: can only concatenate list (not \"int\") to list" - ] - } - ], - "prompt_number": 27 + "outputs": [], + "prompt_number": 56 }, { "cell_type": "code",