Artificial intelligent assistant

二次元配列のリスト内のソート結果が上手く表示されない python [<__main__.gate object at 0x7f89dbc994e0>, <__main__.gate object at 0x7f89dbc99518>, <__main__.gate object at 0x7f89dbc99550>, <__main__.gate object at 0x7f89dbc99588>, <__main__.gate object at 0x7f89dbc995c0>, <__main__.gate object at 0x7f89dbc995f8>, <__main__.gate object at 0x7f89dbc99630>] Gate=(gate(0,2),gate(2,4),gate(0,4),gate(0,2),gate(0,4),gate(0,3),gate(0,2)) Gate class gate(): def __init__(self,target,control): self.tar = target self.con = control Gate = (gate(2,0), gate(2,4), gate(4,0), gate(0,2), gate(4,0), gate(3,0), gate(0,2)) def sort(Gate): gate_sort = [] for g in Gate: if g.tar > g.con: gate_sort.append(gate(g.con, g.tar)) elif g.tar < g.con: gate_sort.append(gate(g.tar, g.con)) return gate_sort print(sort(Gate))

Python 3.6 `f-strings`(PEP 498: Literal String Interpolation)

format


def __repr__(self):
return 'gate({}, {})'.format(self.tar, self.con)


f-strings


def __repr__(self):
return f'gate({self.tar}, {self.con})'

## print(Gate)
Gate = (gate(2,0), gate(2,4), gate(4,0), gate(0,2), gate(4,0), gate(3,0), gate(0,2))
print(Gate)
=>
(gate(2, 0), gate(2, 4), gate(4, 0), gate(0, 2), gate(4, 0), gate(3, 0), gate(0, 2))

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy c2e19e1778c631d8bde43a84ff07953f