On Wed, Aug 28, 2002 at 11:02:25AM -0400, Guido van Rossum wrote: > > Even if all the arguments are re-iterable containers the recursive call > > produces a lazy generator object - the cartesian product of the tail. I > > don't want to read it eagerly into a list. > > And I wasn't proposing that. > > def cartesian(*sequences): > if len(sequences) == 0: > yield [] > else: > head, tail = sequences[:-1], sequences[-1] > tail = list(tail) # <--- This is what I was proposing > for x in cartesian(*head): > for y in tail: > yield x + [y] Silly me. Too much LISPthink made me automatically see "head" as the first item and "tail" as the rest. Now I see that the head is all but the last item and the tail is the last. It was really funny - like seeing the cup change into two faces right in front of your eyes... Oren
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4