1
0
mirror of https://github.com/balkian/gists.git synced 2024-11-01 08:01:44 +00:00
gists/array_combination.ipynb

64 lines
1.6 KiB
Plaintext
Raw Normal View History

2014-02-24 11:39:51 +00:00
{
"metadata": {
"name": "Untitled0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
2014-02-24 11:40:29 +00:00
"input": "a=set([3,4])\nb=set([3,7])",
2014-02-24 11:39:51 +00:00
"language": "python",
"metadata": {},
"outputs": [],
2014-02-24 11:40:29 +00:00
"prompt_number": 112
2014-02-24 11:39:51 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": "def get_nonrepeated(seta, setb):\n for i in seta:\n if i not in setb:\n yield i",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
},
{
"cell_type": "code",
"collapsed": false,
2014-02-24 11:40:29 +00:00
"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)",
2014-02-24 11:39:51 +00:00
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
2014-02-24 11:40:29 +00:00
"text": "[[4, 3], [3, 7], [4, 7]]\n3\n"
2014-02-24 11:39:51 +00:00
}
],
2014-02-24 11:40:29 +00:00
"prompt_number": 115
2014-02-24 11:39:51 +00:00
},
{
"cell_type": "code",
"collapsed": false,
2014-02-24 11:40:29 +00:00
"input": "",
2014-02-24 11:39:51 +00:00
"language": "python",
"metadata": {},
2014-02-24 11:40:29 +00:00
"outputs": [],
"prompt_number": 56
2014-02-24 11:39:51 +00:00
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}