t=[c+s for c in'O A B AB'.split()for s in'-+'] print('',*t,sep='\t') for s in t:print(s,*[['','X'][(y[-1]=='-'or'+'==s[-1])*(y[:-1]in'O'+s[:-1])]for y in t],sep='\t')
Note that non-ascii characters in the above source code will be escaped (such as \x9f).