def child(bird1, bird2):
return 1 <= sum(i != j for i, j in zip(bird1, bird2)) <= 2
def grandchild(bird1, bird2):
return bird1 == bird2 or sum(i != j for i, j in zip(bird1, bird2)) <= 4 and len(bird1) > 1
def diffs(bird1, bird2):
return sum(c1 != c2 for c1, c2 in zip(bird1, bird2))
def child(bird1, bird2):
return diffs(bird1, bird2) in [1, 2]
def grandchild(bird1, bird2):
return diffs(bird1, bird2) in [0, 1, 2, 3, 4] if len(bird1) > 1 else bird1 == bird2
def diff(bird1, bird2):
return sum(c1 != c2 for c1, c2 in zip(bird1, bird2))
def child(bird1, bird2):
return 1 <= diff(bird1, bird2) <= 2
def grandchild(bird1, bird2):
d = diff(bird1, bird2)
if len(bird1) == 1:
return d == 0
return 0 <= d <= 4
from operator import ne
def child(bird1, bird2):
return 1 <= sum(map(ne, bird1, bird2)) <= 2
def grandchild(bird1, bird2):
return sum(map(ne, bird1, bird2)) <= 4 and bird1 + bird2 not in 'BWB'
def d(a, b):
return sum(x != y for x, y in zip(a, b))
def child(a, b):
return 0 < d(a, b) < 3
def grandchild(a, b):
return d(a, b) < 5 and a + b not in 'BWB'
def child(bird1, bird2):
return sum(one != two for one, two in zip(bird1, bird2)) in (2, 1)
def grandchild(bird1, bird2):
if len(bird1) != 1:
return sum(one != two for one, two in zip(bird1, bird2)) in range(5)
return bird1 == bird2
def child(bird1, bird2):
dif = 0
for x, y in zip(bird1, bird2):
if x != y:
dif += 1
if dif in [1, 2]:
return True
else:
return False
def grandchild(bird1, bird2):
dif = 0
for x, y in zip(bird1, bird2):
if x != y:
dif += 1
if len(bird1) == 1:
if dif == 0:
return True
else:
return False
if dif in [0,1,2,3,4]:
return True
else:
return False
f=lambda *A:sum(a!=b for a,b in zip(*A))
child=lambda *A:0<f(*A)<3
grandchild=lambda A,B:A==B or 1<len(A)and f(A,B)<5
f=lambda A,B:sum(a!=b for a,b in zip(A,B))
child=lambda A,B:0<f(A,B)<3
grandchild=lambda A, B:not(len(A)==len(B)==1 and A!=B)and f(A,B)<5
def child(bird1, bird2):
return sum(i!=j for i,j in zip(bird1,bird2)) in [1,2]
def grandchild(bird1, bird2):
s = sum(i!=j for i,j in zip(bird1,bird2))
return s in range(5) if len(bird1) > 1 else not s
景越Python基础训练营QQ群