python - If and only if all given conditions are true -


import numpy np     def data_verify(source):         rows = [x.strip().split(' ') x in open(source)]         columns = zip(*rows)         blocks = np.array(rows).reshape((3,3,3,3)).transpose((0,2,1,3)).reshape((9,9))             #check iff, see further                 return rows, columns, blocks             else:                 return false 

got sudoku grid in txt such:

3 2 7 4 8 1 6 5 9 1 8 9 3 6 5 7 2 4 6 5 4 2 7 9 8 1 3 7 9 8 1 3 2 5 4 6 5 6 3 9 4 7 2 8 1 2 4 1 6 5 8 3 9 7 8 1 2 7 9 3 4 6 5 4 7 5 8 1 6 9 3 2 9 3 6 5 2 4 1 7 8 

the function collects relevant data , return respective rows, columns , blocks iff length of rows same columns' (got few other functions determine whether puzzle legit). figured enough compare first row columns (or vice versa, doesn't make difference). how can create check goes like:

for in range(len(rows)):     if len(row[0]) == len(column[i]):         #do if of lengths check out 

use all:

if all(len(row[0]) == len(column[i]) in range(len(rows))):     #do if of lengths check out 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -