自然三元逻辑?

Ran*_*lue 3 python logic

可能重复:
如何更简洁地找到缺失值?

是否有一种使用Python语言T在字母表中表达交换运算符的好方法a b c,其中

  • a T b == c
  • b T c == a
  • c T a == b

我最好的尝试是硬编码:

def T(first, second):
    if first is 'a' and second is 'b':
        return 'c'
    if first is 'a' and second is 'c':
        return 'c'
    if first is 'b' and second is 'c':
        return 'a'
    if first is 'b' and second is 'a':
        return 'c'
    if first is 'c' and second is 'a':
        return 'b'
    if first is 'c' and second is 'b':
        return 'a'
Run Code Online (Sandbox Code Playgroud)

Ósc*_*pez 10

这个怎么样:

alphabet = set(['a', 'b', 'c'])
def T(x, y):
    return (alphabet - set([x, y])).pop()
Run Code Online (Sandbox Code Playgroud)

像这样使用它:

T('a', 'b')
> 'c'
Run Code Online (Sandbox Code Playgroud)