<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Generating all combinations from an arbitrary number of sequences</title>
	<atom:link href="http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations/feed" rel="self" type="application/rss+xml" />
	<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations</link>
	<description>The personal weblog of Peter Hosey.</description>
	<pubDate>Tue, 07 Oct 2008 18:16:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Brandon Mintern</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-198881</link>
		<dc:creator>Brandon Mintern</dc:creator>
		<pubDate>Sat, 24 May 2008 05:01:44 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-198881</guid>
		<description>FYI if you're coming from Google or whatever, this is in Python 2.6 and 3K as itertools.product (implemented in C).

And I tested the various implementations along with a couple others, and ecombinations was (surprisingly) the clear winner. It makes me want to eschew Python for Lisp... :-)</description>
		<content:encoded><![CDATA[<p>FYI if you're coming from Google or whatever, this is in Python 2.6 and 3K as itertools.product (implemented in C).</p>
<p>And I tested the various implementations along with a couple others, and ecombinations was (surprisingly) the clear winner. It makes me want to eschew Python for Lisp... :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132848</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Thu, 25 Oct 2007 18:27:28 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132848</guid>
		<description>Colin: I wonder whether the list comprehension could be turned into a generator comprehension somehow, possibly relieving the need to call &lt;code&gt;reversed&lt;/code&gt;…</description>
		<content:encoded><![CDATA[<p>Colin: I wonder whether the list comprehension could be turned into a generator comprehension somehow, possibly relieving the need to call <code>reversed</code>…</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Barrett</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132847</link>
		<dc:creator>Colin Barrett</dc:creator>
		<pubDate>Thu, 25 Oct 2007 18:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132847</guid>
		<description>This actually makes it work the way I want it to:

&lt;pre&gt;def combinations(*list):
    r=[[]]
    for x in reversed(list):
        r = [[y]+i for y in x for i in r]
    return r&lt;/pre&gt;

Adding &lt;code&gt;print r&lt;/code&gt; inside the loop reveals how it works:

&lt;pre&gt;&#62;&#62;&#62; combinations([1,2],[3,4],[5,6]) and 'Done'
[[5], [6]]
[[3, 5], [3, 6], [4, 5], [4, 6]]
[[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
'Done'&lt;/pre&gt;

</description>
		<content:encoded><![CDATA[<p>This actually makes it work the way I want it to:</p>
<pre>def combinations(*list):
    r=[[]]
    for x in reversed(list):
        r = [[y]+i for y in x for i in r]
    return r</pre>
<p>Adding <code>print r</code> inside the loop reveals how it works:</p>
<pre>&gt;&gt;&gt; combinations([1,2],[3,4],[5,6]) and 'Done'
[[5], [6]]
[[3, 5], [3, 6], [4, 5], [4, 6]]
[[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
'Done'</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wensheng Wang</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132834</link>
		<dc:creator>Wensheng Wang</dc:creator>
		<pubDate>Thu, 25 Oct 2007 17:37:18 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132834</guid>
		<description>from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496807

&lt;pre&gt;def combinations(*list):
    r=[[]]
    for x in list:
        r = [i+[y] for y in x for i in r]
    return r

print combinations([1,2,3],[4,5,6])
print
print combinations([1,2],[3,4],[5,6])
print
print combinations([1,2,3],[4,5],[6],[7,8,9,10])&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>from: <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496807" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496807</a></p>
<pre>def combinations(*list):
    r=[[]]
    for x in list:
        r = [i+[y] for y in x for i in r]
    return r

print combinations([1,2,3],[4,5,6])
print
print combinations([1,2],[3,4],[5,6])
print
print combinations([1,2,3],[4,5],[6],[7,8,9,10])</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnar Birgisson</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132637</link>
		<dc:creator>Arnar Birgisson</dc:creator>
		<pubDate>Thu, 25 Oct 2007 00:06:03 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132637</guid>
		<description>On a slightly related note, here's how to generate the powerset (all possible subsets) of some set:

&lt;pre&gt;In [103]:
def powerset(S):
	for b in range(1 &#60;&#60; len(S)):
		yield set(e for (i,e) in enumerate(S) if (1&#60;&#60;i)&#38;b)

In [104]: myset = set(range(1,5))

In [105]: list(powerset(myset))
Out[105]: 
[set([]),
 set([1]),
 set([2]),
 set([1, 2]),
 set([3]),
 set([1, 3]),
 set([2, 3]),
 set([1, 2, 3]),
 set([4]),
 set([1, 4]),
 set([2, 4]),
 set([1, 2, 4]),
 set([3, 4]),
 set([1, 3, 4]),
 set([2, 3, 4]),
 set([1, 2, 3, 4])]&lt;/pre&gt;

(Problem suggested by Árni Már)</description>
		<content:encoded><![CDATA[<p>On a slightly related note, here's how to generate the powerset (all possible subsets) of some set:</p>
<pre>In [103]:
def powerset(S):
	for b in range(1 &lt;&lt; len(S)):
		yield set(e for (i,e) in enumerate(S) if (1&lt;&lt;i)&amp;b)

In [104]: myset = set(range(1,5))

In [105]: list(powerset(myset))
Out[105]:
[set([]),
 set([1]),
 set([2]),
 set([1, 2]),
 set([3]),
 set([1, 3]),
 set([2, 3]),
 set([1, 2, 3]),
 set([4]),
 set([1, 4]),
 set([2, 4]),
 set([1, 2, 4]),
 set([3, 4]),
 set([1, 3, 4]),
 set([2, 3, 4]),
 set([1, 2, 3, 4])]</pre>
<p>(Problem suggested by Árni Már)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnar Birgisson</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132503</link>
		<dc:creator>Arnar Birgisson</dc:creator>
		<pubDate>Wed, 24 Oct 2007 09:45:10 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132503</guid>
		<description>It's interesting to see some timings. We basically have two dimensions that can vary, the number of sequences and the lengths of the sequences. Don't have time right now to do it myself, but I propose the following test cases:

&lt;pre&gt;(range(2) for i in range(10))
(range(2) for i in range(100))
(range(2) for i in range(1000))
(range(2) for i in range(10000)) # perhaps to much?
(range(10) for i in range(10))
(range(100) for i in range(10))
(range(10000) for i in range(2))
(range(i) for i in range(10))
(range(i) for i in range(100))&lt;/pre&gt;
etc.

Arnar</description>
		<content:encoded><![CDATA[<p>It's interesting to see some timings. We basically have two dimensions that can vary, the number of sequences and the lengths of the sequences. Don't have time right now to do it myself, but I propose the following test cases:</p>
<pre>(range(2) for i in range(10))
(range(2) for i in range(100))
(range(2) for i in range(1000))
(range(2) for i in range(10000)) # perhaps to much?
(range(10) for i in range(10))
(range(100) for i in range(10))
(range(10000) for i in range(2))
(range(i) for i in range(10))
(range(i) for i in range(100))</pre>
<p>etc.</p>
<p>Arnar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132485</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Wed, 24 Oct 2007 08:39:26 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132485</guid>
		<description>Non-scientific tests:

&lt;pre&gt;&#62;&#62;&#62; c=1
&#62;&#62;&#62; t = time(); list(gcombs(*(range(2) for i in range(18)))) and time() - t
0.87823700904846191
&#62;&#62;&#62; c=1
&#62;&#62;&#62; t = time(); list(gcombs(*(range(2) for i in range(18)))) and time() - t
0.67177414894104004
&#62;&#62;&#62; t = time(); list(icombinations(*(range(2) for i in range(18)))) and time() 
- t
0.68789410591125488
&#62;&#62;&#62; t = time(); list(icombinations(*(range(2) for i in range(18)))) and time() 
- t
0.72254085540771484
&#62;&#62;&#62; t = time(); list(ecombinations(*(range(2) for i in range(18)))) and time() 
- t
0.58095097541809082
&#62;&#62;&#62; t = time(); list(ecombinations(*(range(2) for i in range(18)))) and time() 
- t
0.59889411926269531&lt;/pre&gt;

I wouldn't take these numbers seriously though. In some of my tests, icombinations beat ecombinations.</description>
		<content:encoded><![CDATA[<p>Non-scientific tests:</p>
<pre>&gt;&gt;&gt; c=1
&gt;&gt;&gt; t = time(); list(gcombs(*(range(2) for i in range(18)))) and time() - t
0.87823700904846191
&gt;&gt;&gt; c=1
&gt;&gt;&gt; t = time(); list(gcombs(*(range(2) for i in range(18)))) and time() - t
0.67177414894104004
&gt;&gt;&gt; t = time(); list(icombinations(*(range(2) for i in range(18)))) and time()
- t
0.68789410591125488
&gt;&gt;&gt; t = time(); list(icombinations(*(range(2) for i in range(18)))) and time()
- t
0.72254085540771484
&gt;&gt;&gt; t = time(); list(ecombinations(*(range(2) for i in range(18)))) and time()
- t
0.58095097541809082
&gt;&gt;&gt; t = time(); list(ecombinations(*(range(2) for i in range(18)))) and time()
- t
0.59889411926269531</pre>
<p>I wouldn't take these numbers seriously though. In some of my tests, icombinations beat ecombinations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Godfrey</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132417</link>
		<dc:creator>Gary Godfrey</dc:creator>
		<pubDate>Wed, 24 Oct 2007 05:38:34 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132417</guid>
		<description>I suspect I could add a reverse in there to make it match the for loops.  To be honest, I didn't use this for work - it's far too difficult to read.  It just occurred to me when I was thinking about the problem and I thought it was cute.

I finally ran some profiling.  It seems to be about 16x slower than the recursive solution.  I don't think it's worth updating the variable names :-).

Gary Godfrey
Austin, TX, USA</description>
		<content:encoded><![CDATA[<p>I suspect I could add a reverse in there to make it match the for loops.  To be honest, I didn't use this for work - it's far too difficult to read.  It just occurred to me when I was thinking about the problem and I thought it was cute.</p>
<p>I finally ran some profiling.  It seems to be about 16x slower than the recursive solution.  I don't think it's worth updating the variable names :-).</p>
<p>Gary Godfrey<br />
Austin, TX, USA</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Hosey</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132385</link>
		<dc:creator>Peter Hosey</dc:creator>
		<pubDate>Wed, 24 Oct 2007 04:20:05 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132385</guid>
		<description>&lt;p&gt;Gary: Looks cool, but Colin complains that the order in which combinations are yielded does not match the original nested &lt;code&gt;for&lt;/code&gt; loops.&lt;/p&gt;

&lt;p&gt;Any chance we could get a version with clearer variable names? ☺&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Gary: Looks cool, but Colin complains that the order in which combinations are yielded does not match the original nested <code>for</code> loops.</p>
<p>Any chance we could get a version with clearer variable names? ☺</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary Godfrey</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132354</link>
		<dc:creator>Gary Godfrey</dc:creator>
		<pubDate>Wed, 24 Oct 2007 02:14:50 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132354</guid>
		<description>I needed something like this for work today.  Here's my version - no recursion.  I've not profiled it.

&lt;pre&gt;from itertools import *

c = 1
def cumul(n):
    global c
    r = c
    c *= len(n)
    return r

def gcombs(*s):
    tary = [ cycle(chain(*[ repeat(nn, cumval) for nn in news])) for (news,cumval) in [ (ns, cumul(ns)) for ns in s]]
    tary.append(xrange(0,c))
    t = izip( *tary)
    for v in t:
        yield v[:-1]

print list(gcombs([1,2],[4,5,6],[7,8,9]))&lt;/pre&gt;
</description>
		<content:encoded><![CDATA[<p>I needed something like this for work today.  Here's my version - no recursion.  I've not profiled it.</p>
<pre>from itertools import *

c = 1
def cumul(n):
    global c
    r = c
    c *= len(n)
    return r

def gcombs(*s):
    tary = [ cycle(chain(*[ repeat(nn, cumval) for nn in news])) for (news,cumval) in [ (ns, cumul(ns)) for ns in s]]
    tary.append(xrange(0,c))
    t = izip( *tary)
    for v in t:
        yield v[:-1]

print list(gcombs([1,2],[4,5,6],[7,8,9]))</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132337</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Wed, 24 Oct 2007 00:54:24 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132337</guid>
		<description>(This is fun to mess around with.) The Lisp way to do it:
&lt;pre&gt;def ecombinations(*args):
    n = len(args)
    defun = "def inner(args):"
    for_loops = "\n".join("%sfor v%s in args[%s]:" % ("    "*(i+1), i, i) 
        for i in range(n))
    yield_line = "v%s, " * n % tuple(range(n))
    yield_line = "%syield (%s)" % ("    "*(n+1), yield_line)
    exec '\n'.join([defun, for_loops, yield_line])
    return inner(args)&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>(This is fun to mess around with.) The Lisp way to do it:</p>
<pre>def ecombinations(*args):
    n = len(args)
    defun = "def inner(args):"
    for_loops = "\n".join("%sfor v%s in args[%s]:" % ("    "*(i+1), i, i)
        for i in range(n))
    yield_line = "v%s, " * n % tuple(range(n))
    yield_line = "%syield (%s)" % ("    "*(n+1), yield_line)
    exec '\n'.join([defun, for_loops, yield_line])
    return inner(args)</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132305</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Tue, 23 Oct 2007 23:50:01 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132305</guid>
		<description>(hey, my previous comment got double-escaped since I ignored the CAPTCHA the first time. feel free to delete it, and this parenthetical remark.)

Actually, the previous version goes through items in the wrong order:

&lt;code&gt;&#62;&#62;&#62; print '\n'.join(repr(i) for i in icombinations("12", "ab", "yz"))
('1', 'a', 'y')
('2', 'a', 'y')
('1', 'b', 'y')
('2', 'b', 'y')
('1', 'a', 'z')
('2', 'a', 'z')
('1', 'b', 'z')
('2', 'b', 'z')&lt;/code&gt;

What we actually want is this:

&lt;code&gt;def icombinations(*seqs):
    if len(seqs) == 1:
        for i in seqs[0]: yield (i, )
    else:
        for rest in icombinations(*seqs[:-1]):
            for i in seqs[-1]:
                yield rest + (i, )&lt;/code&gt;

In order to get this output:

&lt;code&gt;&#62;&#62;&#62; print '\n'.join(repr(i) for i in icombinations("12", "ab", "yz"))
('1', 'a', 'y')
('1', 'a', 'z')
('1', 'b', 'y')
('1', 'b', 'z')
('2', 'a', 'y')
('2', 'a', 'z')
('2', 'b', 'y')
('2', 'b', 'z')&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>(hey, my previous comment got double-escaped since I ignored the CAPTCHA the first time. feel free to delete it, and this parenthetical remark.)</p>
<p>Actually, the previous version goes through items in the wrong order:</p>
<p><code>&gt;&gt;&gt; print '\n'.join(repr(i) for i in icombinations("12", "ab", "yz"))<br />
('1', 'a', 'y')<br />
('2', 'a', 'y')<br />
('1', 'b', 'y')<br />
('2', 'b', 'y')<br />
('1', 'a', 'z')<br />
('2', 'a', 'z')<br />
('1', 'b', 'z')<br />
('2', 'b', 'z')</code></p>
<p>What we actually want is this:</p>
<p><code>def icombinations(*seqs):<br />
    if len(seqs) == 1:<br />
        for i in seqs[0]: yield (i, )<br />
    else:<br />
        for rest in icombinations(*seqs[:-1]):<br />
            for i in seqs[-1]:<br />
                yield rest + (i, )</code></p>
<p>In order to get this output:</p>
<p><code>&gt;&gt;&gt; print '\n'.join(repr(i) for i in icombinations("12", "ab", "yz"))<br />
('1', 'a', 'y')<br />
('1', 'a', 'z')<br />
('1', 'b', 'y')<br />
('1', 'b', 'z')<br />
('2', 'a', 'y')<br />
('2', 'a', 'z')<br />
('2', 'b', 'y')<br />
('2', 'b', 'z')</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132304</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Tue, 23 Oct 2007 23:48:37 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132304</guid>
		<description>Actually, the previous version goes through items in the wrong order:

&lt;code&gt;&#62;&#62;&#62; print \'\\n\'.join(repr(i) for i in icombinations(\"12\", \"ab\", \"yz\"))
(\'1\', \'a\', \'y\')
(\'2\', \'a\', \'y\')
(\'1\', \'b\', \'y\')
(\'2\', \'b\', \'y\')
(\'1\', \'a\', \'z\')
(\'2\', \'a\', \'z\')
(\'1\', \'b\', \'z\')
(\'2\', \'b\', \'z\')&lt;/code&gt;

What we actually want is this:

&lt;code&gt;def icombinations(*seqs):
    if len(seqs) == 1:
        for i in seqs[0]: yield (i, )
    else:
        for rest in icombinations(*seqs[:-1]):
            for i in seqs[-1]:
                yield rest + (i, )&lt;/code&gt;

In order to get this output:

&lt;code&gt;&#62;&#62;&#62; print \'\\n\'.join(repr(i) for i in icombinations(\"12\", \"ab\", \"yz\"))
(\'1\', \'a\', \'y\')
(\'1\', \'a\', \'z\')
(\'1\', \'b\', \'y\')
(\'1\', \'b\', \'z\')
(\'2\', \'a\', \'y\')
(\'2\', \'a\', \'z\')
(\'2\', \'b\', \'y\')
(\'2\', \'b\', \'z\')&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Actually, the previous version goes through items in the wrong order:</p>
<p><code>&gt;&gt;&gt; print \'\\n\'.join(repr(i) for i in icombinations(\"12\", \"ab\", \"yz\"))<br />
(\'1\', \'a\', \'y\')<br />
(\'2\', \'a\', \'y\')<br />
(\'1\', \'b\', \'y\')<br />
(\'2\', \'b\', \'y\')<br />
(\'1\', \'a\', \'z\')<br />
(\'2\', \'a\', \'z\')<br />
(\'1\', \'b\', \'z\')<br />
(\'2\', \'b\', \'z\')</code></p>
<p>What we actually want is this:</p>
<p><code>def icombinations(*seqs):<br />
    if len(seqs) == 1:<br />
        for i in seqs[0]: yield (i, )<br />
    else:<br />
        for rest in icombinations(*seqs[:-1]):<br />
            for i in seqs[-1]:<br />
                yield rest + (i, )</code></p>
<p>In order to get this output:</p>
<p><code>&gt;&gt;&gt; print \'\\n\'.join(repr(i) for i in icombinations(\"12\", \"ab\", \"yz\"))<br />
(\'1\', \'a\', \'y\')<br />
(\'1\', \'a\', \'z\')<br />
(\'1\', \'b\', \'y\')<br />
(\'1\', \'b\', \'z\')<br />
(\'2\', \'a\', \'y\')<br />
(\'2\', \'a\', \'z\')<br />
(\'2\', \'b\', \'y\')<br />
(\'2\', \'b\', \'z\')</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Carl</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132231</link>
		<dc:creator>Carl</dc:creator>
		<pubDate>Tue, 23 Oct 2007 19:12:02 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132231</guid>
		<description>Canonical version?

&lt;pre&gt;def icombinations(*seqs):
    if len(seqs) == 1:
        for i in seqs[0]: yield (i, )
    else:
        for rest in icombinations(*seqs[1:]):
            for i in seqs[0]:
                yield (i, ) + rest&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Canonical version?</p>
<pre>def icombinations(*seqs):
    if len(seqs) == 1:
        for i in seqs[0]: yield (i, )
    else:
        for rest in icombinations(*seqs[1:]):
            for i in seqs[0]:
                yield (i, ) + rest</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnar Birgisson</title>
		<link>http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132194</link>
		<dc:creator>Arnar Birgisson</dc:creator>
		<pubDate>Tue, 23 Oct 2007 15:45:23 +0000</pubDate>
		<guid isPermaLink="false">http://boredzo.org/blog/archives/2007-10-22/generating-all-combinations#comment-132194</guid>
		<description>Brian, that's nice. I would have used tuples if I were to use it in my code - but left it as lists here to match the interface in the OP. Didn't realize the speed difference though, but that certainly makes sense.</description>
		<content:encoded><![CDATA[<p>Brian, that's nice. I would have used tuples if I were to use it in my code - but left it as lists here to match the interface in the OP. Didn't realize the speed difference though, but that certainly makes sense.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.229 seconds -->
