Re: Permutations with generators

2007-07-21 Thread Bjoern Schliessmann
Pablo Torres wrote: > AttributeError: 'NoneType' object has no attribute 'insert' > > Could somebody please explain to me why my p variable has no type > at all? It does have a type, NoneType. As already explained, only None normally is of type NoneType. Regards, Björn -- BOFH excuse #281:

Re: Permutations with generators

2007-07-20 Thread Pablo Torres
> > list.insert returns None. Thus, except in the one-element case, your > generator is yielding None all the time. > Oh god...silly me. Thank you guys for the help :) P.S I'm dead stubborn, so here's what I did to fix my code: def perm(seq): "Reshuffles the elements of seq in every pos

Re: Permutations with generators

2007-07-20 Thread Paul Rubin
Pablo Torres <[EMAIL PROTECTED]> writes: > def perm(seq): > "Reshuffles the elements of seq in every possible way" > if len(seq) == 1: > yield seq > else: > for p in perm(seq[1:]): > for i in range(len(seq)): >

Re: Permutations with generators

2007-07-20 Thread Dan Bishop
On Jul 21, 12:42 am, Pablo Torres <[EMAIL PROTECTED]> wrote: > Hey guys! > For the last couple of days, I've been fighting a war against > generators and they've beaten the crap out of me several times. What I > want to do is implement one that yields every possible permutation of > a given sequenc

Re: Permutations with generators

2007-07-20 Thread Pablo Torres
Just a quick P.S: This WOULD NOT work with strings, because of seq.insert() In very other aspect, I'm still lost. -- http://mail.python.org/mailman/listinfo/python-list

Permutations with generators

2007-07-20 Thread Pablo Torres
Hey guys! For the last couple of days, I've been fighting a war against generators and they've beaten the crap out of me several times. What I want to do is implement one that yields every possible permutation of a given sequence (I had lists in mind, but I could swear that this would work on strin