Haskell -> Python
Dave Angel
d at davea.name
Fri Nov 2 18:24:57 EDT 2012
On 11/02/2012 05:40 PM, Ian Kelly wrote:
> On Fri, Nov 2, 2012 at 1:19 PM, <foster63 at gmail.com> 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 from (head + [x] + tail for x in range(heap))
>
> "yield from" is Python 3.3 syntax. If you're not using Python 3.3,
> then that line could be replaced by:
>
> for x in range(heap):
> yield head + [x] + tail
>
> Cheers,
> Ian
Perhaps range(heap) should be replaced by range(len(heap))
--
DaveA
More information about the Python-list
mailing list