Re: (newbie) N-uples from list of lists

2005-12-02 Thread bonono
Martin Miller wrote: > I'd be interested in seeing the one liner using reduce you mentioned -- > how it might be done that way isn't obvious to me. > > Another aspect of Taschuk's solution I like and think is important is > the fact that it is truly iterative in the sense that calling it > returns

Re: (newbie) N-uples from list of lists

2005-12-02 Thread Martin Miller
I'd be interested in seeing the one liner using reduce you mentioned -- how it might be done that way isn't obvious to me. Another aspect of Taschuk's solution I like and think is important is the fact that it is truly iterative in the sense that calling it returns a generator which will yield eac

Re: (newbie) N-uples from list of lists

2005-11-30 Thread bonono
Interesting, I found a reduce one liner(just one step further of Raymond's) easiest to understand and match my thinking about what the problem is about. That once again tell me that different people think and approach the problem differently. It is possible to talk about one "fastest" way, but man

Re: (newbie) N-uples from list of lists

2005-11-30 Thread Martin Miller
FWIW, I found Steven Taschuk's solution easiest to understand regarding the question posed in your original post -- namely how to solve the problem non-recursively with generators -- because it was similar to my own thinking about how to do it -- but suspect that Raymond Hettinger's is the likely t

Re: (newbie) N-uples from list of lists

2005-11-29 Thread vd12005
great thanks to all. actually i have not seen it was a cross product... :) but then there are already few others ideas from the web, i paste what i have found below... BTW i was unable to choose the best one, speaking about performance which one should be prefered ? ### -

Re: (newbie) N-uples from list of lists

2005-11-25 Thread [EMAIL PROTECTED]
This is my attempt : def cross(seq): r=[[]] for x in seq: r = [ a + b for a in r for b in [[i] for i in x ]] return r It is not very efficient though as it would loop through the intermediate list produced multiple times. [EMAIL PROTECTED] wrote: > Hello, > > i think it coul

Re: (newbie) N-uples from list of lists

2005-11-23 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: ... > > An example of recursion elimination in Python can be found at > > > > > Thanks, so it seems that it is only doing the "stacking" oneself rather > than relies on the recurs

Re: (newbie) N-uples from list of lists

2005-11-23 Thread [EMAIL PROTECTED]
Alex Martelli wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Out of curiousity, is "recursion" the desirable way(or is it pythonic > > way) ? How would one do it in the imperative way ? > > For an inherently recursive problem (as this one appears to be), the > traditional alternative

Re: (newbie) N-uples from list of lists

2005-11-23 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Out of curiousity, is "recursion" the desirable way(or is it pythonic > way) ? How would one do it in the imperative way ? For an inherently recursive problem (as this one appears to be), the traditional alternative to recursion is maintaining your o

Re: (newbie) N-uples from list of lists

2005-11-23 Thread [EMAIL PROTECTED]
Out of curiousity, is "recursion" the desirable way(or is it pythonic way) ? How would one do it in the imperative way ? Dan Bishop wrote: > > it could be done by a recursive call, but i am interested in using and > > understanding generators. > > def cross(*args): >"""Iterates over the set cr

Re: (newbie) N-uples from list of lists

2005-11-23 Thread Dan Bishop
[EMAIL PROTECTED] wrote: > Hello, > > i think it could be done by using itertools functions even if i can not > see the trick. i would like to have all available "n-uples" from each > list of lists. > example for a list of 3 lists, but i should also be able to handle any > numbers of items (any len

(newbie) N-uples from list of lists

2005-11-23 Thread vd12005
Hello, i think it could be done by using itertools functions even if i can not see the trick. i would like to have all available "n-uples" from each list of lists. example for a list of 3 lists, but i should also be able to handle any numbers of items (any len(lol)) lol = (['a0', 'a1', 'a2'], ['b