Re: list of all possible values

2009-07-16 Thread Mensanator
On Jul 16, 11:49 am, "Andreas Tawn" wrote: > > > Certainly possible with list comprehensions. > > > a = "abc" > > [(x, y) for x in a for y in a] > > > [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', > 'c'), > > > ('c', 'a'), ('c', 'b'), ('c', 'c')] > > > > But I like b

RE: list of all possible values

2009-07-16 Thread Andreas Tawn
> > Certainly possible with list comprehensions. > > > a = "abc" > [(x, y) for x in a for y in a] > > [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), > > ('c', 'a'), ('c', 'b'), ('c', 'c')] > > > > But I like bearophile's version better. > > > > Andreas, > > Tha

Re: list of all possible values

2009-07-16 Thread David Gibb
> Certainly possible with list comprehensions. > a = "abc" [(x, y) for x in a for y in a] > [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), > ('c', 'a'), ('c', 'b'), ('c', 'c')] > > But I like bearophile's version better. > Andreas, Thanks, but I think you were

RE: list of all possible values

2009-07-14 Thread Andreas Tawn
> David Gibb: > > For example: if my values are ['a', 'b', 'c'], then all possible lists > > of length 2 would be: aa, ab, ac, ba, bb, bc, ca, cb, cc. > > >>> from itertools import product > >>> list(product("abc", repeat=2)) > [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', > '

Re: list of all possible values

2009-07-13 Thread David Gibb
> Or on systems with list comps try: > V='abc' ['%s%s'%(ii,jj) for ii in V for jj in V] > ['aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'] Yeah, except that the length here is hard-coded. There's no way (as far as I can tell, at least), to make this generic with respect to lis

Re: list of all possible values

2009-07-13 Thread Emile van Sebille
On 7/13/2009 9:33 AM Tim Chase said... For example: if my values are ['a', 'b', 'c'], then all possible lists of length 2 would be: aa, ab, ac, ba, bb, bc, ca, cb, cc. I created a recursive program to do it, but I was wondering if there was a better way of doing it (possibly with list comprehens

Re: list of all possible values

2009-07-13 Thread Bearophile
David Gibb: > For example: if my values are ['a', 'b', 'c'], then all possible lists > of length 2 would be: aa, ab, ac, ba, bb, bc, ca, cb, cc. >>> from itertools import product >>> list(product("abc", repeat=2)) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('c', 'a'),

Re: list of all possible values

2009-07-13 Thread Tim Chase
For example: if my values are ['a', 'b', 'c'], then all possible lists of length 2 would be: aa, ab, ac, ba, bb, bc, ca, cb, cc. I created a recursive program to do it, but I was wondering if there was a better way of doing it (possibly with list comprehensions). Here's my recursive version: va