Re: Generating list of possible configurations
- From: Terry Reedy <tjreedy@xxxxxxxx>
- Date: Wed, 02 Jul 2008 20:40:52 -0400
Mensanator wrote:
On Jul 2, 4:53 pm, "bjorklund.e...@xxxxxxxxx"
<bjorklund.e...@xxxxxxxxx> wrote:
After this I tried figuring out a function that would generate the
different possible configurations, but I couldn't quite wrap my head
around it...
Lookup "Cartesian Product".
Any pointers as to how one would go about
solving something like this would be greatly appreciated.
for a in [True,False]:
for b in [True,False]:
for c in [1,2,3,4]:
print 'combined settings:',a,'\t',b,'\t',c
This has been added to itertools at least for 2.6/3.0
>>> import itertools as it
>>> for prod in it.product((True,False), (True,False), (1,2,3,4)):
print(prod) # or run test
(True, True, 1)
(True, True, 2)
(True, True, 3)
(True, True, 4)
(True, False, 1)
(True, False, 2)
(True, False, 3)
(True, False, 4)
(False, True, 1)
(False, True, 2)
(False, True, 3)
(False, True, 4)
(False, False, 1)
(False, False, 2)
(False, False, 3)
(False, False, 4)
The sequences of sequences can, of course, be a variable:
>>> options = ((True,False), (True,False), (1,2,3,4))
>>> for prod in it.product(*options): print(prod)
does the same thing. So you can change 'options' without changing the test runner.
tjr
.
- Follow-Ups:
- Re: Generating list of possible configurations
- From: Bruno Desthuilliers
- Re: Generating list of possible configurations
- References:
- Generating list of possible configurations
- From: bjorklund.emil@xxxxxxxxx
- Re: Generating list of possible configurations
- From: Mensanator
- Generating list of possible configurations
- Prev by Date: Re: wrong md5 checksum
- Next by Date: wxPython: How can I get window's HANDLE in wxPython.
- Previous by thread: Re: Generating list of possible configurations
- Next by thread: Re: Generating list of possible configurations
- Index(es):
Relevant Pages
|