






from heapq import heappop, heappush

import numpy as np





def    __lowerCAmelCase   (    __snake_case       ,			__snake_case       ,			__snake_case       ,			__snake_case       ,			):
     __lowerCAmelCase      ,			__lowerCAmelCase             =       grid.shape
     __lowerCAmelCase             =       [-1, 1, 0, 0]
     __lowerCAmelCase             =       [0, 0, -1, 1]
     if allow_diagonal:
          dx += [-1, -1, 1, 1]
          dy += [-1, 1, -1, 1]

     __lowerCAmelCase      ,			__lowerCAmelCase             =       [(0, source)], set()
     __lowerCAmelCase             =       np.full((rows, cols)       ,			np.inf							)
     __lowerCAmelCase             =       0
     __lowerCAmelCase             =       np.empty((rows, cols)       ,			dtype=__snake_case							)
     __lowerCAmelCase             =       None

     while queue:
          ((__lowerCAmelCase)      ,			(__lowerCAmelCase))             =       heappop(__snake_case							)
          if (x, y) in visited:
               continue
          visited.add((x, y)							)

          if (x, y) == destination:
               __lowerCAmelCase             =       []
               while (x, y) != source:
                    path.append((x, y)							)
                    __lowerCAmelCase      ,			__lowerCAmelCase             =       predecessors[x, y]
               path.append(__snake_case							)  # add the source manually
               path.reverse()
               return matrix[destination], path

          for i in range(len(__snake_case							)							):
               __lowerCAmelCase      ,			__lowerCAmelCase             =       x + dx[i], y + dy[i]
               if 0 <= nx < rows and 0 <= ny < cols:
                    __lowerCAmelCase             =       grid[nx][ny]
                    if next_node == 1 and matrix[nx, ny] > dist + 1:
                         heappush(__snake_case       ,			(dist + 1, (nx, ny))							)
                         __lowerCAmelCase             =       dist + 1
                         __lowerCAmelCase             =       (x, y)

     return np.inf, []


if __name__ == "__main__":
 import doctest

 doctest.testmod()














from __future__ import annotations

import csv

import requests
from bsa import BeautifulSoup





def    __lowerCAmelCase   (    __snake_case = ""							):
     __lowerCAmelCase             =       url or "https://www.imdb.com/chart/top/?ref_=nv_mv_250"
     __lowerCAmelCase             =       BeautifulSoup(requests.get(__snake_case							).text       ,			"html.parser"							)
     __lowerCAmelCase             =       soup.find_all("td"       ,			attrs="titleColumn"							)
     __lowerCAmelCase             =       soup.find_all("td"       ,			class_="ratingColumn imdbRating"							)
     return {
         title.a.text: float(rating.strong.text							)
         for title, rating in zip(__snake_case       ,			__snake_case							)
     }





def    __lowerCAmelCase   (    __snake_case = "IMDb_Top_250_Movies.csv"							):
     __lowerCAmelCase             =       get_imdb_top_aaa_movies()
     with open(__snake_case       ,			"w"       ,			newline=""							) as out_file:
          __lowerCAmelCase             =       csv.writer(__snake_case							)
          writer.writerow(["Movie title", "IMDb rating"]							)
          for title, rating in movies.items():
               writer.writerow([title, rating]							)


if __name__ == "__main__":
 write_movies()






