I currently just use something like this:
def match9(a,b,c,d,e,f,g,h,i):
if a==b and b==c and c==d and d==e and e==f and f==g and g==h and h==i:
return 1
else:
return 0
in conjunction with
temp = match9(d1s1,d1s2,d1s3,d1s4,d1s5,d1s6,d1s7,d1s8,d1s9)
if temp == 1:
codeToBeActivated()