Skip to content

Instantly share code, notes, and snippets.

@lpenguin
Last active August 29, 2015 14:09
Show Gist options
  • Save lpenguin/e86e0d65b74c34617c62 to your computer and use it in GitHub Desktop.
Save lpenguin/e86e0d65b74c34617c62 to your computer and use it in GitHub Desktop.
{
"metadata": {
"name": "",
"signature": "sha256:da85fe4b1722ac997645f8af9888f4c3bae14dd9cb630421133dcfa6372ef829"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"def arrange(items, count):\n",
" if count == 0:\n",
" return []\n",
"# print \"choose() items: \"+str(items)+\", count: \"+str(count)\n",
" res = []\n",
" i = 0\n",
" for item in items:\n",
" subres = arrange(items[:i]+items[i+1:], count - 1)\n",
" if not subres:\n",
" res.append([item])\n",
" for rest in subres:\n",
" res.append([item] + rest)\n",
" i += 1\n",
" \n",
" return res\n",
"def print_sets(sets):\n",
" for subset in sets:\n",
" print subset\n",
"print_sets(arrange(['a', 'b', 'c', 'd'], 4))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"['a', 'b', 'c', 'd']\n",
"['a', 'b', 'd', 'c']\n",
"['a', 'c', 'b', 'd']\n",
"['a', 'c', 'd', 'b']\n",
"['a', 'd', 'b', 'c']\n",
"['a', 'd', 'c', 'b']\n",
"['b', 'a', 'c', 'd']\n",
"['b', 'a', 'd', 'c']\n",
"['b', 'c', 'a', 'd']\n",
"['b', 'c', 'd', 'a']\n",
"['b', 'd', 'a', 'c']\n",
"['b', 'd', 'c', 'a']\n",
"['c', 'a', 'b', 'd']\n",
"['c', 'a', 'd', 'b']\n",
"['c', 'b', 'a', 'd']\n",
"['c', 'b', 'd', 'a']\n",
"['c', 'd', 'a', 'b']\n",
"['c', 'd', 'b', 'a']\n",
"['d', 'a', 'b', 'c']\n",
"['d', 'a', 'c', 'b']\n",
"['d', 'b', 'a', 'c']\n",
"['d', 'b', 'c', 'a']\n",
"['d', 'c', 'a', 'b']\n",
"['d', 'c', 'b', 'a']\n"
]
}
],
"prompt_number": 48
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"a = [1, 2, 3, 4, 5]\n",
"a[:2]+ a[3:]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 29,
"text": [
"[1, 2, 4, 5]"
]
}
],
"prompt_number": 29
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment