473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Generating list of possible configurations

Hello pythonistas.

I'm a newbie to pretty much both programming and Python. I have a task
that involves writing a test script for every possible combination of
preference settings for a software I'm testing. I figured that this
was something that a script could probably do pretty easily, given all
the various possibilites.

I started creating a dictionary of all the settings, where each key
has a value that is a list of the possible values for that setting.
Most of the settings are simple booleans (setting is on or off), some
of them are drop-downs with several values. For example:

settings = {
'setting_a': (True, False),
'setting_b': (True, False),
'setting_c': (1, 2, 3, 4),
}

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... Are there any general patterns/structures that are suited
for this type of task? Any pointers as to how one would go about
solving something like this would be greatly appreciated. It's not
that I really need to use Python for it, but I thought it could be a
good learning excercise... :-)

Kind regards,
//Emil
Jul 2 '08 #1
14 1978
On Jul 2, 4:53*pm, "bjorklund.e...@gmail.com"
<bjorklund.e...@gmail.comwrote:
Hello pythonistas.

I'm a newbie to pretty much both programming and Python. I have a task
that involves writing a test script for every possible combination of
preference settings for a software I'm testing. I figured that this
was something that a script could probably do pretty easily, given all
the various possibilites.

I started creating a dictionary of all the settings, where each key
has a value that is a list of the possible values for that setting.
Most of the settings are simple booleans (setting is on or off), some
of them are drop-downs with several values. For example:

settings = {
* * 'setting_a': (True, False),
* * 'setting_b': (True, False),
* * 'setting_c': (1, 2, 3, 4),

}

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...
Basically, for each setting of a, you must do each possible b,
and for each a,b setting you must do each possible c, etc.
Are there any general patterns/structures that are suited
for this type of task?
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

combined settings: True True 1
combined settings: True True 2
combined settings: True True 3
combined settings: True True 4
combined settings: True False 1
combined settings: True False 2
combined settings: True False 3
combined settings: True False 4
combined settings: False True 1
combined settings: False True 2
combined settings: False True 3
combined settings: False True 4
combined settings: False False 1
combined settings: False False 2
combined settings: False False 3
combined settings: False False 4

It's not
that I really need to use Python for it, but I thought it could be a
good learning excercise... :-)
You may, then, also be interested in

Permutations with Replacement
Permutations without Replacement
Combinations with Replacement
Combinations without Replacement
>
Kind regards,
//Emil
Jul 2 '08 #2


Mensanator wrote:
On Jul 2, 4:53 pm, "bjorklund.e...@gmail.com"
<bjorklund.e...@gmail.comwrote:
>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

Jul 3 '08 #3
Terry Reedy a écrit :
>

Mensanator wrote:
(snip)
>Lookup "Cartesian Product".
(snip)
>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

Great !
Jul 3 '08 #4
On Jul 2, 5:53*pm, "bjorklund.e...@gmail.com"
<bjorklund.e...@gmail.comwrote:
Hello pythonistas.

I'm a newbie to pretty much both programming and Python. I have a task
that involves writing a test script for every possible combination of
preference settings for a software I'm testing. I figured that this
was something that a script could probably do pretty easily, given all
the various possibilites.

I started creating a dictionary of all the settings, where each key
has a value that is a list of the possible values for that setting.
Most of the settings are simple booleans (setting is on or off), some
of them are drop-downs with several values. For example:

settings = {
* * 'setting_a': (True, False),
* * 'setting_b': (True, False),
* * 'setting_c': (1, 2, 3, 4),

}

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... Are there any general patterns/structures that are suited
for this type of task? Any pointers as to how one would go about
solving something like this would be greatly appreciated. It's not
that I really need to use Python for it, but I thought it could be a
good learning excercise... :-)

Kind regards,
//Emil
http://www.artfulcode.net/articles/s...ations-python/
Jul 3 '08 #5
On Jul 3, 2:13�am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
Terry Reedy a �crit :
Mensanator wrote:
(snip)
Lookup "Cartesian Product".
(snip)
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

Great !
Well, it will be great at some point in the future
when Python 2.6/3.0 have actually been released and
third party extensions such as gmpy have caught up.

Until then, such solutions are worthless, i.e., of
no value.
Jul 3 '08 #6


Mensanator wrote:
On Jul 3, 2:13�am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
>Terry Reedy a �crit :
>>This has been added to itertools at least for 2.6/3.0
Great !

Well, it will be great at some point in the future
when Python 2.6/3.0 have actually been released and
The betas 'have actually been released' and I am happily using 3.0. The
core features that I care about have mostly been untouched and where
they have, they work.
third party extensions such as gmpy have caught up.
Not my personal concern. And certainly not a direct concern for nearly
all uses of itertools.product.
Until then, such solutions are worthless, i.e., of no value.
Why are you so anxious to generalize your personal negative views to
everyone else. Worthless to you, worthwhile to me. And for someone who
does not need cross-products today or in the next few months,
potentially valuable information for when the final releases do arrive,
maybe in September.

tjr

Jul 3 '08 #7
On Jul 3, 2:52Â*pm, Terry Reedy <tjre...@udel.eduwrote:
Mensanator wrote:
On Jul 3, 2:13�am, Bruno Desthuilliers <bruno.
42.desthuilli...@websiteburo.invalidwrote:
Terry Reedy a �crit :
This has been added to itertools at least for 2.6/3.0
Great !
Well, it will be great at some point in the future
when Python 2.6/3.0 have actually been released and

The betas 'have actually been released' and I am happily using 3.0. Â*
But you're not using it for production work. Unless you're ignoring
the recommendations.
The
core features that I care about have mostly been untouched and where
they have, they work.
That's not the issue.
>
third party extensions such as gmpy have caught up.

Not my personal concern. Â*
Right. Which is why your 3.0 specific advice is worthless.
Those ARE personal concerns of just about everyone else.
And certainly not a direct concern for nearly
all uses of itertools.product.
Until then, such solutions are worthless, i.e., of no value.

Why are you so anxious to generalize your personal negative views to
everyone else. Â*
Not to everyone else, to the new and inexperienced Pyhton users.
Maybe you don't remember what it was like being a new user where
you need to have such things pointed out to you. And I'm not being
negative, just realistic. If I ask a question today, I want an
answer I can use tomorrow, not one I can use six months from now.
Worthless to you, worthwhile to me. Â*
The OP's opinion is the only one that matters. What do you suppose
is the percentage of posts on this newsgroup by those using 3.0?
And for someone who
does not need cross-products today or in the next few months,
potentially valuable information for when the final releases do arrive,
maybe in September.
That's fine for them. It's been said here that they will be a minority
for a long time.
>
tjr
Jul 3 '08 #8
On Jul 3, 5:49*pm, Mensanator <mensana...@aol.comwrote:
On Jul 3, 2:52*pm, Terry Reedy <tjre...@udel.eduwrote:
Worthless to you, worthwhile to me. *

The OP's opinion is the only one that matters.
I bet the OP doesn't know (or care) what gmpy is.
What do you suppose
is the percentage of posts on this newsgroup by those using 3.0?
Taking into account 2.6 too (we're not talking about only 3.0 here),
probably not much less than those who even know what is gmpy, let
alone dismiss a beta Python release because their obscure pet module
is not available yet.
You will probably sound less negative if you refrain from projecting
your own very specialized needs to those of the average pythonista.

George
Jul 3 '08 #9
On Jul 3, 6:24*pm, George Sakkis <george.sak...@gmail.comwrote:
On Jul 3, 5:49*pm, Mensanator <mensana...@aol.comwrote:
On Jul 3, 2:52*pm, Terry Reedy <tjre...@udel.eduwrote:
Worthless to you, worthwhile to me. *
The OP's opinion is the only one that matters.

I bet the OP doesn't know (or care) what gmpy is.
But he'll care if he tries to use something specific to
2.6 and it fails and he doesn't know why.
>
What do you suppose
is the percentage of posts on this newsgroup by those using 3.0?

Taking into account 2.6 too (we're not talking about only 3.0 here),
probably not much less than those who even know what is gmpy, let
alone dismiss a beta Python release because their obscure pet module
is not available yet.
That was just an example. When you consider ALL the pet
modules like PIL, Numpy, Win32, etc., that's a lot, isn't it.
You will probably sound less negative if you refrain from projecting
your own very specialized needs to those of the average pythonista.
Funny how you don't complain when Mr. Reedy projects HIS
specialized needs to the average pythonista.

I was just trying to be helpful (I admit I often sound
negative when I'm not trying to be).
>
George
Jul 3 '08 #10
On Jul 3, 6:54*am, Mensanator <mensana...@aol.comwrote:
>
Well, it will be great at some point in the future
when Python 2.6/3.0 have actually been released and
third party extensions such as gmpy have caught up.

Until then, such solutions are worthless, i.e., of
no value.
gmpy is supported on Python 2.6. A new version and Windows binaries
were released shortly after 2.6b1 was released.

casevh
Jul 4 '08 #11
On Jul 3, 7:51 pm, Mensanator <mensana...@aol.comwrote:
On Jul 3, 6:24 pm, George Sakkis <george.sak...@gmail.comwrote:
Taking into account 2.6 too (we're not talking about only 3.0 here),
probably not much less than those who even know what is gmpy, let
alone dismiss a beta Python release because their obscure pet module
is not available yet.

That was just an example. When you consider ALL the pet
modules like PIL, Numpy, Win32, etc., that's a lot, isn't it.
A few points:
- The OP acknowledged he's a newbie, and as a newbie he'll probably
spend some time getting used to the language and the standard library
before jumping to the dozens 3rd party packages.
- I am sure many Python users are productive without ever touching an
external package; that is after all the point of "batteries included".
- Even if they do have external dependencies, chances are that they
are pure Python modules, which typically work without modification on
new 2.x versions.
I was just trying to be helpful (I admit I often sound
negative when I'm not trying to be).
Well, something like "Until then, such solutions are worthless, i.e.,
of no value" is too strong, subjective and biased to be really
helpful.

George
Jul 4 '08 #12
On Jul 3, 8:10�pm, casevh <cas...@gmail.comwrote:
On Jul 3, 6:54�am, Mensanator <mensana...@aol.comwrote:
Well, it will be great at some point in the future
when Python 2.6/3.0 have actually been released and
third party extensions such as gmpy have caught up.
Until then, such solutions are worthless, i.e., of
no value.

gmpy is supported on Python 2.6. A new version and Windows binaries
were released shortly after 2.6b1 was released.
Great!

Looks like I'll be installing 2.6 this weekend.
>
casevh
Jul 4 '08 #13
On Jul 3, 9:09�pm, George Sakkis <george.sak...@gmail.comwrote:
On Jul 3, 7:51 pm, Mensanator <mensana...@aol.comwrote:
On Jul 3, 6:24 pm, George Sakkis <george.sak...@gmail.comwrote:
Taking into account 2.6 too (we're not talking about only 3.0 here),
probably not much less than those who even know what is gmpy, let
alone dismiss a beta Python release because their obscure pet module
is not available yet.
That was just an example. When you consider ALL the pet
modules like PIL, Numpy, Win32, etc., that's a lot, isn't it.

A few points:
- The OP acknowledged he's a newbie, and as a newbie he'll probably
spend some time getting used to the language and the standard library
before jumping to the dozens 3rd party packages.
- I am sure many Python users are productive without ever touching an
external package; that is after all the point of "batteries included".
- Even if they do have external dependencies, chances are that they
are pure Python modules, which typically work without modification on
new 2.x versions.
Yes, these points are valid, although I think
mine are valid also. But there's no point in any
further arguing.
>
I was just trying to be helpful (I admit I often sound
negative when I'm not trying to be).

Well, something like "Until then, such solutions are worthless, i.e.,
of no value" is too strong, subjective and biased to be really
helpful.
I was trying NOT to imply "broken" or "doesn't
do anything useful". I guess I'll have to try to
be less succinct.
>
George
Jul 4 '08 #14
Wow, I didn't have time to look back on this thread for a while,
surprised of the activity. Anyhow, thanks for the answers, and thanks
for pointing out that the itertools-variants are not available in 2.5.

Cheers!

//emil
Jul 4 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return...
5
by: Ross MacGregor | last post by:
I have a very simple yet complicated problem. I want to generate a random list of indices (int's) for a container. Let's say I have a container with 10 items and I want a list of 3 random...
2
by: Kevin McNeish [C# MVP] | last post by:
Does anyone know how to set the project constants property for "All Configurations" programmatically? The following code does this by setting each project individually: foreach...
7
by: Venus | last post by:
Hello, I am trying to generate a dynamic form at runtime and would like to do it using "<asp: ..." form elements as follows Build up the string that is placed somewhere in the HTML code the...
8
by: Mir Nazim | last post by:
Hello, I need to write scripts in which I need to generate all posible unique combinations of an integer list. Lists are a minimum 12 elements in size with very large number of possible...
9
by: =?ISO-8859-1?Q?BJ=F6rn_Lindqvist?= | last post by:
With regexps you can search for strings matching it. For example, given the regexp: "foobar\d\d\d". "foobar123" would match. I want to do the reverse, from a regexp generate all strings that could...
0
by: Dmitrii | last post by:
My C# project has 4-configuration: Debug, Release, DebugPlus, and ReleasePlus. In each of these configurations the C# program should consume (be "linked" to) a different Assembly.dll build...
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
20
MMcCarthy
by: MMcCarthy | last post by:
This problem was proposed to me but not really my area of expertise so I thought I would open it up to the forum to see if anyone had any bright ideas. The problem is generating Microsoft Word...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.