A puzzle for Pythonistas
Magnus Lie Hetland
mlh at furu.idi.ntnu.no
Thu Feb 6 17:13:57 EST 2003
In article <slrnb43kc0.fvh.mlh at furu.idi.ntnu.no>, Magnus Lie Hetland wrote:
>In article <b68f71a7.0301310459.31539d3c at posting.google.com>, Alan
>James Salmoni wrote:
[snip]
>from numarray import compress
>def subsets(seq):
> n = len(seq)
> for i in xrange(2**n):
> cond = [bool(2<<j & i) for j in xrange(n)]
Ehm... The bool(...) is quite redundant. Just use the bit manipulation
expression on its own :)
> yield compress(cond, seq)
--
Magnus Lie Hetland "Nothing shocks me. I'm a scientist."
http://hetland.org -- Indiana Jones
More information about the Python-list
mailing list