simultaneous assignment

Diez B. Roggisch deets at nospam.web.de
Tue May 2 13:25:18 EDT 2006


John Salerno wrote:

> Diez B. Roggisch wrote:
> 
>> I can't imagine what you're actually after here, but assuming that you
>> really need this
> 
> Hard to explain because I'm still trying to figure out how to do it
> myself. I'm trying to solve a little puzzle using Python, even though
> I'm sure it's not necessary. Basically W, X, Y and Z are propositions
> that are either true or false, and the puzzle lists a few statements
> such as "Exactly one of X, Y and Z is true", and I'm trying to work out
> a little algorithm that might test for this kind of stuff.

Then use a Proposition-class that holds the actual value.
 
> Another thing I'm trying to do is write a function that tests to see if
> a list contains exactly one true item, and the rest are false (obviously
> this would have to be a list of boolean values, I guess).

No - you can for example override the comparison-semantics on the
Proposition-class to be comparable with True/False with the proper
semantics:




class Proposition(object):

    def __init__(self, v):
        self._v = v


    def __eq__(self, o):
        return self._v == o


TrueProposition = Proposition(True)
FalseProposition = Proposition(False)

print True == TrueProposition
print False == TrueProposition
print False == FalseProposition



Diez



More information about the Python-list mailing list