transactions=[{'A','B'},{'A','B'},{'A','B'},{'A'},{'B'},{'B','C'}]
def metrics(antecedent,consequent):
    if not antecedent or not consequent or antecedent & consequent:
        raise ValueError('nonempty disjoint itemsets required')
    n=len(transactions)
    a=sum(antecedent<=t for t in transactions)
    c=sum(consequent<=t for t in transactions)
    both=sum((antecedent|consequent)<=t for t in transactions)
    if not a or not c:
        raise ValueError('undefined confidence or lift')
    support=both/n
    confidence=both/a
    lift=confidence/(c/n)
    return support,confidence,lift
ab=metrics({'A'},{'B'})
ba=metrics({'B'},{'A'})
print('A->B',ab)
print('B->A',ba)
assert ab[0]==0.5 and ab[1]==0.75
assert abs(ab[2]-0.9)<1e-12
assert ba[1]==0.6 and abs(ba[2]-ab[2])<1e-12
