itertools product(infinite iterator) hangs
Oscar Benjamin
oscar.j.benjamin at gmail.com
Sun Sep 15 19:55:56 EDT 2019
On Sat, 14 Sep 2019 at 07:22, ast <none at gmail.com> wrote:
>
> Le 14/09/2019 à 04:26, Oscar Benjamin a écrit :
> >
> > What am I missing?
>
> here is a pseudo code for product:
>
> def product(*args, repeat=1):
> # product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
> # product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
> pools = [tuple(pool) for pool in args] * repeat
> result = [[]]
> for pool in pools:
> result = [x+[y] for x in result for y in pool]
> for prod in result:
> yield tuple(prod)
>
> clearly "tuple(pool)" hangs with an infinite iterable pool
Thanks for this response. I also realised this myself after a while.
Actually I didn't see your message until I posted my own followup
reply because gmail had moved it into spam. Apparently it doesn't like
the headers in your email for some reason: "Gmail could not verify
that it actually came from gmail.com. Avoid clicking links,
downloading attachments or replying with personal information."
Oscar
More information about the Python-list
mailing list