How can I shorten this python code analyzing a 3d grid?
Python 3, 108 107 bytes
Since the cube only contains the strings &quot;X&quot; and &quot;Z&quot;, there are only two valid cube patterns. The one that starts with XZXZX... and the one that starts with ZXZXZ....
My solutions generates these 2 cubes and checks if the inputted cube is one of them.
def golf(l):L=len(l);r=range(L);return l in[[[list(&quot;XZ&quot;*L)[(i+j+k)%2:][:L]for j in r]for k in r]for i in r]
i iterates over the possible cubes. Since the dimension is at least 2, we can reuse r instead of writing for i in(0,1).