Re: Haskell -> Python

2012-11-03 Thread Aahz
In article , wrote: > >def options( heaps ): > >if heaps == []: return [] > >head, tail = heaps[:1], heaps[1:] > ># Calculate all possible moves which is the sum of ># prepending all possible head "moves" to the tail ># and appending all possible tail "moves" to the

Re: Haskell -> Python

2012-11-03 Thread Duncan Booth
Ian Kelly wrote: > On Fri, Nov 2, 2012 at 1:19 PM, wrote: >> Is there anything anyone could recommend to make it more "Pythonic" >> or more functional. It looks clumsy next to the Haskell. > > def options(heaps): > for i, heap in enumerate(heaps): > head = heaps[:i] > tai

Re: Haskell -> Python

2012-11-02 Thread Dave Angel
On 11/02/2012 06:27 PM, Ian Kelly wrote: > On Fri, Nov 2, 2012 at 4:24 PM, Dave Angel wrote: >> Perhaps range(heap) should be replaced by range(len(heap)) > "heaps" is a list of ints per the OP, so "heap" is an int. You're right of course . I was distracted by the fact that a heap is normally a

Re: Haskell -> Python

2012-11-02 Thread Ian Kelly
On Fri, Nov 2, 2012 at 4:24 PM, Dave Angel wrote: > Perhaps range(heap) should be replaced by range(len(heap)) "heaps" is a list of ints per the OP, so "heap" is an int. -- http://mail.python.org/mailman/listinfo/python-list

Re: Haskell -> Python

2012-11-02 Thread Dave Angel
On 11/02/2012 05:40 PM, Ian Kelly wrote: > On Fri, Nov 2, 2012 at 1:19 PM, wrote: >> Is there anything anyone could recommend to make it more "Pythonic" or more >> functional. It looks clumsy next to the Haskell. > def options(heaps): > for i, heap in enumerate(heaps): > head = heap

Re: Haskell -> Python

2012-11-02 Thread Ian Kelly
On Fri, Nov 2, 2012 at 3:40 PM, Ian Kelly wrote: > On Fri, Nov 2, 2012 at 1:19 PM, wrote: >> Is there anything anyone could recommend to make it more "Pythonic" or more >> functional. It looks clumsy next to the Haskell. > > def options(heaps): > for i, heap in enumerate(heaps): >

Re: Haskell -> Python

2012-11-02 Thread Ian Kelly
On Fri, Nov 2, 2012 at 1:19 PM, wrote: > Is there anything anyone could recommend to make it more "Pythonic" or more > functional. It looks clumsy next to the Haskell. def options(heaps): for i, heap in enumerate(heaps): head = heaps[:i] tail = heaps[i+1:] yield fro

Re: Haskell -> Python

2012-11-02 Thread Simon Foster
On 02/11/12 19:56, Dave Angel wrote: On 11/02/2012 03:19 PM, foste...@gmail.com wrote: Hi All, As part of a Nim solver I'm playing around with I'm trying to code this Haskell snippet: options [x] = zero : [ [y] | y <- [1..x - 1] ] options (x:xs) = map (++ xs) (options [x]) ++ map (x:) (

Re: Haskell -> Python

2012-11-02 Thread Dave Angel
On 11/02/2012 03:19 PM, foste...@gmail.com wrote: > Hi All, > > As part of a Nim solver I'm playing around with I'm trying to code this > Haskell snippet: > > options [x] = zero : [ [y] | y <- [1..x - 1] ] > options (x:xs) = map (++ xs) (options [x]) ++ map (x:) (options xs) > > in Python. So

Haskell -> Python

2012-11-02 Thread foster63
Hi All, As part of a Nim solver I'm playing around with I'm trying to code this Haskell snippet: options [x] = zero : [ [y] | y <- [1..x - 1] ] options (x:xs) = map (++ xs) (options [x]) ++ map (x:) (options xs) in Python. So far I have this, which works OK, but somehow doesn't feel right