Best Python code snippet using pandera_python
checkioFindShip.py
Source:checkioFindShip.py
...23 search(land_map, x + 1, y, c, xx)24 if land_map[x + 1][y + 1] == c:25 search(land_map, x + 1, y + 1, c, xx)26 return land_map27def check_io(land_map1: List[List[int]]) -> List[int]:28 x = 129 d = []30 land_map = [[0 for i in range(len(land_map1[0]) + 2)] for c in range(len(land_map1) + 2)]31 for i in range(len(land_map1)):32 for c in range(len(land_map1[0])):33 land_map[i + 1][c + 1] = land_map1[i][c]34 for c in range(1, len(land_map) - 1):35 for ii in range(1, len(land_map[0]) - 1):36 if land_map[c][ii] == 1:37 x += 138 land_map = search(land_map, c, ii, 1, x)39 print()40 for i in land_map:41 print(i)42 land_map = [str(y) for x in land_map for y in x if y != 0]43 for i in range(2, 30):44 if ' '.join(land_map).count(str(i)):45 d.append(' '.join(land_map).count(str(i)))46 print(sorted(d))47 return sorted(d)48if __name__ == '__main__':49 print("Example:")50 check_io([[1, 0, 0, 0, 0],51 [0, 0, 1, 1, 0],52 [0, 0, 0, 1, 0],53 [0, 1, 1, 0, 0]])54 check_io([[0, 0, 0, 1, 0, 0],55 [1, 0, 0, 1, 1, 1],56 [1, 0, 0, 1, 1, 0],57 [0, 0, 1, 0, 1, 0],58 [0, 0, 1, 1, 1, 0],59 [0, 1, 1, 1, 1, 1],60 [0, 0, 0, 0, 1, 1]])61 check_io([[0, 0, 0, 0, 0, 0],62 [0, 1, 1, 1, 0, 0],63 [0, 1, 0, 1, 0, 0],64 [0, 1, 1, 1, 0, 0],65 [0, 0, 0, 0, 0, 0],66 [0, 1, 0, 0, 1, 0],67 [0, 1, 0, 1, 1, 1],68 [0, 0, 0, 0, 1, 0]])69 check_io([[1],70 [1],71 [1],72 [1],73 [1],74 [1],75 [1],76 [1],77 [1]])78 check_io([[1, 0, 1, 0, 0, 1],79 [0, 0, 0, 0, 1, 0],80 [1, 0, 1, 1, 0, 1],81 [1, 0, 1, 0, 0, 1],82 [0, 0, 1, 0, 0, 1],83 [1, 0, 1, 0, 1, 1]])84 #85 # assert checkio([[0, 0, 0, 0, 0],86 # [0, 0, 1, 1, 0],87 # [0, 0, 0, 1, 0],88 # [0, 1, 0, 0, 0],89 # [0, 0, 0, 0, 0]]) == [1, 3], "1st example"90 # assert checkio([,[0 0, 0, 0, 0],91 # [0, 0, 1, 1, 0],92 # [0, 0, 0, 1, 0],...
checker.py
Source:checker.py
1import torch2import logging3def CHECK2D(tensor):4 assert(len(tensor.shape) == 2), 'get {} {}'.format(tensor.shape, len(tensor.shape)) 5 return tensor.shape 6def CHECK4D(tensor):7 assert(len(tensor.shape) == 4), 'get {} {}'.format(tensor.shape, len(tensor.shape))8 return tensor.shape 9def CHECK5D(tensor):10 assert(len(tensor.shape) == 5), 'get {} {}'.format(tensor.shape, len(tensor.shape))11 return tensor.shape 12def CHECK3D(tensor):13 assert(len(tensor.shape) == 3), 'get {} {}'.format(tensor.shape, len(tensor.shape))14 return tensor.shape 15def CHECKSIZE(tensor, size):16 if isinstance(size, torch.Tensor):17 assert(tensor.shape == size.shape), ' get {} {}'.format(tensor.shape, size.shape)18 else:19 assert(tensor.shape == torch.Size(size)), tensor.shape20def CHECKEQ(a, b,s=None):21 assert(a == b), 'get {} {}'.format(a, b)22 if not (a == b):23 print('get {} {}'.format(a, b))24 if s:25 print(s)26 else: 27 assert(False)28def CHECKABSST(a, b):29 """ check if abs(a) < b """30 # assert(abs(a) < b), 'get {} {}'.format(a, b)31 if not (abs(a) < b):32 print('get {} {}'.format(a, b))33def CHECKEQT(a,b):34 CHECKEQ(a.shape, b.shape)35 CHECKEQ((a-b).sum(), 0)36def CHECKINFO(tensor,mode,info):37 for i in range(len(mode)):38 k = mode[i]39 if k.isdigit():40 v = int(k)41 else:42 v = info[k]43 assert(tensor.shape[i] == v), 'i{} k{} v{} get {}'.format(44 i,k,v,tensor.shape45 )46def CHECKBOX(a, b):47 a = a.cpu()48 b = b.cpu()49 assert(a.size == b.size), '{} {}'.format(a, b)50 CHECKEQ(a.bbox.shape, b.bbox.shape)51 CHECKEQ((a.bbox - b.bbox).sum(), 0)52def CHECKDEBUG(dmm_io, check_io, depth=0):53 """ check if every thing in A-list equal to B-list """54 if depth == 0 and type(dmm_io) == dict:55 return CHECKDEBUG([dmm_io], [check_io], depth=0)56 assert(type(dmm_io) == list)57 assert(type(check_io) == list)58 CHECKEQ(len(dmm_io), len(check_io))59 # logging.info(' '*(depth+1) + '>'*depth)60 for cid, (icur, iprev) in enumerate(zip(dmm_io, check_io)):61 depthstr = ' '*(depth+1) + '| ' + '[%d-%d]'%(depth, cid)62 logging.info(depthstr + '-')63 # logging.info(depthstr + 'cid: %d'%cid)64 if isinstance(icur, torch.Tensor):65 # logging.info(depthstr + 'check tensor: {}'.format(icur.shape))66 CHECKEQ(icur.shape, iprev.shape)67 CHECKEQ(icur.sum(), iprev.sum())68 # CHECKEQ(icur.mean(), iprev.mean())69 #CHECKEQ(icur.min(), iprev.min())70 #CHECKEQ(icur.max(), iprev.max())71 elif type(icur) == tuple:72 CHECKDEBUG(list(icur), list(iprev), depth+1)73 elif type(icur) == list:74 CHECKDEBUG(icur, iprev, depth+1) # list of list .. 75 elif type(icur) == dict:76 for name in icur.keys():77 logging.info(depthstr + 'dname: {}'.format(name))78 CHECKDEBUG([icur[name]], [iprev[name]], depth+1)79 #elif type(icur) == str:80 # CHECKEQ(icur, iprev)81 else:82 logging.info(depthstr + '{}'.format(type(icur)))83 CHECKEQ(icur, iprev) # none special type84 # logging.info(' '*(depth+1) + '<'*depth)...
checkioXO.py
Source:checkioXO.py
...4 return True5 if a == b == c == "O":6 return True7 return False8def check_io(game_map):9 if f(game_map[0][0], game_map[1][0], game_map[2][0]):10 return game_map[0][0]11 if f(game_map[0][1], game_map[1][1], game_map[2][1]):12 return game_map[0][1]13 if f(game_map[0][2], game_map[1][2], game_map[2][2]):14 return game_map[0][2]15 if f(game_map[0][0], game_map[0][1], game_map[0][2]):16 return game_map[0][0]17 if f(game_map[1][0], game_map[1][1], game_map[1][2]):18 return game_map[1][0]19 if f(game_map[2][0], game_map[2][1], game_map[2][2]):20 return game_map[2][0]21 if f(game_map[0][2], game_map[1][1], game_map[2][0]):22 return game_map[0][2]23 if f(game_map[2][2], game_map[1][1], game_map[0][0]):24 return game_map[2][2]25 return 'D'26if __name__ == '__main__':27 print("Example:")28 print(check_io([".OX","..X",".OX"]))29 print(check_io([30 "X.O",31 "XX.",32 "XOO"]))33 print(check_io([34 "OO.",35 "XOX",36 "XOX"])) # == "O", "Os wins"37 print(' ', check_io([38 "OOX",39 "XXO",40 "OXX"])) # == "D", "Draw"41 print(check_io([42 "O.X",43 "XX.",44 "XOO"])) # == "X", "Xs wins again"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!