Skip to main content
Added code formating
Source Link

I have the following list of variables that take on a Boolean value:

outcome_value=['A','B','C']
outcome_type=[True,False]

I want to obtain the full list for possible outcomes for the three variables. The conditions I want are when A=True then B,C = False; when B=True the others equal False and so on. in other words:

outcomes_all = [(True, False, False), (False, True, False), (False, False, True)]

What code could I use to obtain the above? Please note this is a simplification of what I am looking to do I am looking to get code I could use to extend to a more complex list of outcomes.

Only thing i can think of so far is as follows

import random
        for o in outcome_value:
            p=random.choice(outcome_type)
            print(p)

which of course only produces one set of True False values and can produce more than one True value which I don't want. I have been trying to build out if statements as well but keep running down blind alleys with it.

Does anyone have any ideas on how to do this? Haven't seen any threads with a similar question yet.

Thanks


Edit: thinkI may have oversimplified my questions so will post a more complex example

outcome_value=['A','B','C','D','E','F']
outcome_type=[True,False]

I'm looking for all possible permutations of True and False but want to specify conditions such as:

  1. outcome_type of A must not equal outcome_type of B, same for C and D, E and F

  2. if A=True, then C,E must equal False (in addition to condition 1 for B being met also)

  3. if C=True, A,E=False (in addition to condition 1 for D being met also)

  4. if E=True, A,C=False (in addition to condition 1 for F being met also)

Therefore final outcome would be like follows:

[(True, False, False, True ,False ,True), (False, True, False, False, False ,True), (False, False, True, True, True, False)]

Hope that makes sense.

I have the following list of variables that take on a Boolean value:

outcome_value=['A','B','C']
outcome_type=[True,False]

I want to obtain the full list for possible outcomes for the three variables. The conditions I want are when A=True then B,C = False; when B=True the others equal False and so on. in other words:

outcomes_all = [(True, False, False), (False, True, False), (False, False, True)]

What code could I use to obtain the above? Please note this is a simplification of what I am looking to do I am looking to get code I could use to extend to a more complex list of outcomes.

Only thing i can think of so far is as follows

import random
        for o in outcome_value:
            p=random.choice(outcome_type)
            print(p)

which of course only produces one set of True False values and can produce more than one True value which I don't want. I have been trying to build out if statements as well but keep running down blind alleys with it.

Does anyone have any ideas on how to do this? Haven't seen any threads with a similar question yet.

Thanks

I have the following list of variables that take on a Boolean value:

outcome_value=['A','B','C']
outcome_type=[True,False]

I want to obtain the full list for possible outcomes for the three variables. The conditions I want are when A=True then B,C = False; when B=True the others equal False and so on. in other words:

outcomes_all = [(True, False, False), (False, True, False), (False, False, True)]

What code could I use to obtain the above? Please note this is a simplification of what I am looking to do I am looking to get code I could use to extend to a more complex list of outcomes.

Only thing i can think of so far is as follows

import random
        for o in outcome_value:
            p=random.choice(outcome_type)
            print(p)

which of course only produces one set of True False values and can produce more than one True value which I don't want. I have been trying to build out if statements as well but keep running down blind alleys with it.

Does anyone have any ideas on how to do this? Haven't seen any threads with a similar question yet.

Thanks


Edit: thinkI may have oversimplified my questions so will post a more complex example

outcome_value=['A','B','C','D','E','F']
outcome_type=[True,False]

I'm looking for all possible permutations of True and False but want to specify conditions such as:

  1. outcome_type of A must not equal outcome_type of B, same for C and D, E and F

  2. if A=True, then C,E must equal False (in addition to condition 1 for B being met also)

  3. if C=True, A,E=False (in addition to condition 1 for D being met also)

  4. if E=True, A,C=False (in addition to condition 1 for F being met also)

Therefore final outcome would be like follows:

[(True, False, False, True ,False ,True), (False, True, False, False, False ,True), (False, False, True, True, True, False)]

Hope that makes sense.

I have the following list of variables that take on a Boolean value:

''' outcome_value=['A','B','C'] ''' ''' outcome_type=[True,False] '''

outcome_value=['A','B','C']
outcome_type=[True,False]

I want to obtain the full list for possible outcomes for the three variables. The conditions I want are when A=True then B,C = False; when B=True the others equal False and so on. in other words:

''' outcomes_all = [(True, False, False), (False, True, False), (False, False, True)] '''

outcomes_all = [(True, False, False), (False, True, False), (False, False, True)]

What code could I use to obtain the above? Please note this is a simplification of what I am looking to do I am looking to get code I could use to extend to a more complex list of outcomes.

Only thing i can think of so far is as follows

''' import random for o in outcome_value: p=random.choice(outcome_type) print(p) '''

import random
        for o in outcome_value:
            p=random.choice(outcome_type)
            print(p)

which of course only produces one set of True False values and can produce more than one True value which I don't want. I have been trying to build out if statements as well but keep running down blind alleys with it.

Does anyone have any ideas on how to do this? Haven't seen any threads with a similar question yet.

Thanks

I have the following list of variables that take on a Boolean value:

''' outcome_value=['A','B','C'] ''' ''' outcome_type=[True,False] '''

I want to obtain the full list for possible outcomes for the three variables. The conditions I want are when A=True then B,C = False; when B=True the others equal False and so on. in other words:

''' outcomes_all = [(True, False, False), (False, True, False), (False, False, True)] '''

What code could I use to obtain the above? Please note this is a simplification of what I am looking to do I am looking to get code I could use to extend to a more complex list of outcomes.

Only thing i can think of so far is as follows

''' import random for o in outcome_value: p=random.choice(outcome_type) print(p) '''

which of course only produces one set of True False values and can produce more than one True value which I don't want. I have been trying to build out if statements as well but keep running down blind alleys with it.

Does anyone have any ideas on how to do this? Haven't seen any threads with a similar question yet.

Thanks

I have the following list of variables that take on a Boolean value:

outcome_value=['A','B','C']
outcome_type=[True,False]

I want to obtain the full list for possible outcomes for the three variables. The conditions I want are when A=True then B,C = False; when B=True the others equal False and so on. in other words:

outcomes_all = [(True, False, False), (False, True, False), (False, False, True)]

What code could I use to obtain the above? Please note this is a simplification of what I am looking to do I am looking to get code I could use to extend to a more complex list of outcomes.

Only thing i can think of so far is as follows

import random
        for o in outcome_value:
            p=random.choice(outcome_type)
            print(p)

which of course only produces one set of True False values and can produce more than one True value which I don't want. I have been trying to build out if statements as well but keep running down blind alleys with it.

Does anyone have any ideas on how to do this? Haven't seen any threads with a similar question yet.

Thanks

Source Link

Python Permutations - Obtaining full set of outcomes with conditions

I have the following list of variables that take on a Boolean value:

''' outcome_value=['A','B','C'] ''' ''' outcome_type=[True,False] '''

I want to obtain the full list for possible outcomes for the three variables. The conditions I want are when A=True then B,C = False; when B=True the others equal False and so on. in other words:

''' outcomes_all = [(True, False, False), (False, True, False), (False, False, True)] '''

What code could I use to obtain the above? Please note this is a simplification of what I am looking to do I am looking to get code I could use to extend to a more complex list of outcomes.

Only thing i can think of so far is as follows

''' import random for o in outcome_value: p=random.choice(outcome_type) print(p) '''

which of course only produces one set of True False values and can produce more than one True value which I don't want. I have been trying to build out if statements as well but keep running down blind alleys with it.

Does anyone have any ideas on how to do this? Haven't seen any threads with a similar question yet.

Thanks