Best Python code snippet using autotest_python
views.py
Source:views.py  
...12@csrf_exempt13@allow_http("GET", "POST")14def xinha_linker_backend(request):15    site = request.site16    def recursive_walk(path):17        files = []18        for subpath in site.get_contents(path):19            data = {'url': subpath}20            file_path = os.path.join(site.repo_path, path, subpath)21            if os.path.isdir(file_path):22                data['children'] = recursive_walk(subpath)23            files.append(data)24        return files25    26    files = recursive_walk('')27    return HttpResponse(json.dumps(files), mimetype="application/json")28import imghdr29@csrf_exempt30@allow_http("GET", "POST")31@rendered_with("xinha/image_manager.html")32def xinha_image_manager_backend(request):33    return {}34from PIL import Image35@csrf_exempt36@allow_http("GET", "POST")37@rendered_with("xinha/image_manager_images.html")38def xinha_image_manager_backend_images(request):39    site = request.site40    def recursive_walk(path):41        files = []42        for subpath in site.get_contents(path):43            file_path = os.path.join(site.repo_path, subpath)44            if os.path.isdir(file_path):45                files.extend(recursive_walk(subpath))46            elif imghdr.what(file_path) is not None:47                image = Image.open(file_path)48                width, height = image.size49                files.append({50                        'path': '/' + subpath.lstrip('/'),51                        'thumb_uri': '/' + subpath.lstrip('/'),52                        'title': os.path.basename(file_path),53                        'description': os.path.basename(file_path),54                        'id': subpath,55                        'width': width, 'height': height,56                        })57        return files58    59    images = recursive_walk(site.raw_files_path.strip('/'))60    return {'images': images}61@csrf_exempt62def xinha_image_manager_backend_upload(request):...12.py
Source:12.py  
...3import aocd4import tulun5YEAR = 20216DAY = 127def recursive_walk(node, dest, visit_limit=1, visited=None):8    if node is dest:9        return 110    if visited is None:11        visited = collections.defaultdict(int)12        visited[node] = 100013    path_list = []14    for neighbor in node:15        new_visit_limit = visit_limit16        if neighbor.k.islower():17            if visited[neighbor] >= visit_limit:18                continue19            if visited[neighbor] == visit_limit - 1:20                new_visit_limit = max(visit_limit - 1, 1)21        visited[neighbor] += 122        num_child_path = recursive_walk(neighbor, dest, new_visit_limit, visited)23        visited[neighbor] -= 124        path_list.append(num_child_path)25    return sum(path_list)26def main():27    data = """start-A28start-b29A-c30A-b31b-d32A-end33b-end"""34    data = """dc-end35HN-start36start-kj37dc-start38dc-HN39LN-dc40HN-end41kj-sa42kj-HN43kj-dc"""44    data = """fs-end45he-DX46fs-he47start-DX48pj-DX49end-zg50zg-sl51zg-pj52pj-he53RW-he54fs-DX55pj-RW56zg-RW57start-pj58he-WI59zg-he60pj-fs61start-RW"""62    data = aocd.get_data(day=DAY, year=YEAR)63    edges = [l.split('-') for l in data.split('\n')]64    cave_graph = tulun.Graph(edges)65    answer = recursive_walk(cave_graph['start'], cave_graph['end'], visit_limit=1)66    print(answer)67    aocd.submit(answer, part='a', day=DAY, year=YEAR)68    answer = recursive_walk(cave_graph['start'], cave_graph['end'], visit_limit=2)69    print(answer)70    aocd.submit(answer, part='b', day=DAY, year=YEAR)71if __name__ == '__main__':...labirinto_recursivo.py
Source:labirinto_recursivo.py  
...8        [0, 1, 0, 1, 1, 1],9        [0, 1, 0, 0, 0, 0]]10        11#Algoritmo Recursivo de explorar o Labirinto12def recursive_walk(x, y):13    if grid[x][y] == 2:14        print ("Encontrado em:", x, y)15        return True16    17    elif grid[x][y] == 1:18        print ("Parede em:", x, y)19        return False2021    elif grid[x][y] == 3:22        print ("Visitado em:", x, y)23        return False24    25    print ("Visitando em:", x, y)2627    # marca como visitado28    grid[x][y] = 32930    # explora os vizinhos no sentido horario, começando pela direita31    if ((x < len(grid)-1 and recursive_walk(x+1, y))32        or (y > 0 and recursive_walk(x, y-1))33        or (x > 0 and recursive_walk(x-1, y))34        or (y < len(grid)-1 and recursive_walk(x, y+1))):35    		return True3637    return False3839recursive_walk(5, 0)4041print()42print("Da uma olhada no labirinto")
...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!!
