我想知道有没有什么方法可以用更简单,更简洁的方式来写这个方法。
def get(self, t:tuple=None):
for _t in self.tuples:
if t is not None:
condition = False
for i in range(0, len(t) - 1):
if t[i] is not None and t[i] != _t[i]:
condition = True
if condition:
continue
yield _t
如果我读的是你的原稿,
def get(self, t: tuple = None):
if t is None:
yield from self.tuples
return
for _t in self.tuples:
if not all(
si is None or si == ti
for (si, ti) in zip(_t, t)
):
yield _t
或许可以换个说法。