Hi All
With your help I found lots of good method and algorithm. Also I found out
if I exchange all for loop with while loop it make the program much faster
and also it consumes less memory (almost half!)
Just wanna thank you all.
Cheers,
Arash
On 7/13/07, Mark Dickinson <[EMAIL PROTECTED]> wrot
If you don't care about the order of the results, you can use a Gray
code (http://en.wikipedia.org/wiki/Gray_code): this has the advantage
of only adding or removing a single element to get from one subset to
the next.
def powerset(s):
d = dict(zip(
(1<>> list(powerset('abc'))
[set
On 7/12/07, Arash Arfaee <[EMAIL PROTECTED]> wrote:
> I need a powerset generator function. It's really slow with recursion. Does
> anybody have any idea or code(!!) to do it in an acceptable time?
> Thanks
> -Arash
Here's a much simpler (and faster) solution I got from a coworker:
s = range(18)
On Fri, 2007-07-13 at 17:38 +, Jyotirmoy Bhattacharya wrote:
> On Jul 13, 6:34 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > def recursive_powerset(s):
> > if not s: yield set()
> > for x in s:
> > s2 = s - set([x])
> > for subset in recursive_powerset(s2):
> >
On Jul 13, 6:34 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> def recursive_powerset(s):
> if not s: yield set()
> for x in s:
> s2 = s - set([x])
> for subset in recursive_powerset(s2):
> yield subset
> yield subset.union(set([x]))
>
Your recursive_
On Fri, 2007-07-13 at 08:15 -0400, I wrote:
> [...]
> def recursive_powerset(s):
> if not s: yield set()
> for x in s:
> s2 = s - set([x])
> for subset in recursive_powerset(s2):
> yield subset
> for subset in recursive_powerset(s2):
> yield s
On 13 Jul 2007 02:25:59 -0700, Paul Rubin wrote
> Antoon Pardon <[EMAIL PROTECTED]> writes:
> > On 7/12/07, Arash Arfaee <[EMAIL PROTECTED]> wrote:
> > > I need a powerset generator function. It's really slow with recursion.
> > > Does
> > > anybody have any idea or code(!!) to do it in an accepta
Antoon Pardon <[EMAIL PROTECTED]> writes:
> On 7/12/07, Arash Arfaee <[EMAIL PROTECTED]> wrote:
> > I need a powerset generator function. It's really slow with recursion. Does
> > anybody have any idea or code(!!) to do it in an acceptable time?
> My idea would be the following. ...
> 3) let n rang
On 7/12/07, Arash Arfaee <[EMAIL PROTECTED]> wrote:
> I need a powerset generator function. It's really slow with recursion. Does
> anybody have any idea or code(!!) to do it in an acceptable time?
> Thanks
My idea would be the following.
1) Turn your set into a list: lst
2) let lng be the numbe
On 7/12/07, Evan Klitzke <[EMAIL PROTECTED]> wrote:
> On 7/12/07, Arash Arfaee <[EMAIL PROTECTED]> wrote:
> > I need a powerset generator function. It's really slow with recursion. Does
> > anybody have any idea or code(!!) to do it in an acceptable time?
> > Thanks
> > -Arash
>
> I thought that th
On 7/12/07, Arash Arfaee <[EMAIL PROTECTED]> wrote:
> I need a powerset generator function. It's really slow with recursion. Does
> anybody have any idea or code(!!) to do it in an acceptable time?
> Thanks
> -Arash
I thought that this was a really interesting question, so I wrote up a
solution th
On Thu, 12 Jul 2007 21:33:11 -0700, Arash Arfaee wrote
> I need a powerset generator function. It's really slow with recursion. Does
anybody have any idea or code(!!) to do it in an acceptable time?
1) Don't use recursion.
2) Google is your friend.
-Carsten
--
http://mail.python.org/mailman/
I need a powerset generator function. It's really slow with recursion. Does
anybody have any idea or code(!!) to do it in an acceptable time?
Thanks
-Arash
--
http://mail.python.org/mailman/listinfo/python-list
13 matches
Mail list logo