Code extracted from : https://www.redblobgames.com/pathfinding/a-star/implementation.html
Just open a terminal and execute the python files :
python3 1-bfs-graph.py
python3 2-bfs-grid.py
python3 3-dijkstra.py
python3 4-astar.py
The code is commented. The original article also has C++, C#, and links to Go and Rust implementations