1
0
mirror of https://github.com/balkian/gists.git synced 2024-11-23 01:52:27 +00:00
gists/repos/9186870/array_combination.ipynb
J. Fernando Sánchez 44c3bd604a Add 'repos/9186870/' from commit '9cfc2da26524287f6166cc20ca88ad568f762143'
git-subtree-dir: repos/9186870
git-subtree-mainline: 766153a055
git-subtree-split: 9cfc2da265
2021-10-30 15:13:59 +02:00

38 lines
1.1 KiB
Plaintext

{
"metadata": {
"name": "Untitled0"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": "a=set([3,4])\nb=set([3,7])\nc=set([4])\n",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": "def array_combinations(*args):\n combinations = [set([i]) for i in set(args[0])]\n for arg in args[1:]:\n tempcomb = []\n for i in set(arg):\n for c in combinations:\n c.update([i])\n tempcomb.append(c)\n if tempcomb:\n combinations = tempcomb\n return combinations\nres = array_combinations(a,b,c)\nprint res\nprint len(res)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "[set([3, 4, 7]), set([3, 4, 7]), set([3, 4, 7]), set([3, 4, 7])]\n4\n"
}
],
"prompt_number": 25
}
],
"metadata": {}
}
]
}