473,732 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2004
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((Tru e,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(*opt ions): 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.i nvalidwrote:
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.i nvalidwrote:
>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.produ ct.
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.e duwrote:
Mensanator wrote:
On Jul 3, 2:13�am, Bruno Desthuilliers <bruno.
42.desthuilli.. .@websiteburo.i nvalidwrote:
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.produ ct.
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.e duwrote:
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.e duwrote:
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

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

Similar topics

0
1789
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 dict() print combo2(5)
5
2901
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 indices for that container. So I need to generate 3 unique numbers from integer range . There seems to be no simple and efficient way to do this. Any implementation I have come up with involves maintaining a list of
2
1970
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 (EnvDTE.Configuration config in proj.ConfigurationManager) { if
7
3582
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 same way like regular input fields can. strForm = "<form name=""myForm"" runat=""server"">" & vbCrLf strForm += "<asp:button name=""myName"" .... runat=""server"" />" & vbCrLf
8
5635
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 combination(12!) I hacked a few lines of code and tried a few things from Python CookBook (http://aspn.activestate.com/ASPN/Cookbook/), but they are hell slow.
9
6894
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 match it. The regexp: "{3}\d{3}" should generate the strings "AAA000", "AAA001", "AAA002" ... "AAB000", "AAB001" ... "ZZZ999". Is this possible to do? Obviously, for some regexps the set of matches is unbounded (a list of everything that...
0
1406
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 created by a C++/CLI multiple configuration project:: Debug, Release, DebugPlus, and ReleasePlus Assembly.dll, respectively. So far I could not find a way to do this.
8
2594
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; m_ResultArray.Add ( aFoundObject);
20
8327
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 Documents on a server from Word templates and injecting data from a data source. There are a number of solutions to this problem that are less than satisfactory: 1. Use the Microsoft Word Object Model is not good as it requires the installation of a...
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8773
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.