The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

2

collections.deque() The documentation for collections.deque() says it is more efficient than a list when appending/popping elements. (Popping the 0th element from a list, may cause the rest of the list to be copied forward one space.) So use a deque instead of a list for the queue. set() Use a set() instead of a list() for the adjacent nodes. Also use a ...


4

There are a few PEP8 issues: In Python3, class definitions have been overhauled a bit, and one can simply do class Node: instead of class Node(object):. The spacing is a bit all over the place: there should be two blank lines between class definitions, and I find the spacing within def bfs(self, start_node) difficult. The naming convention is to be ...


3

In your private static int TryDirection(int[][] grid, int x, int y, Queue<int[]> Q, int countFreshOranges) method I would invert the logic: If the given coordinate is valid and the field contains a fresh orange, then do something: private static int TryDirection(int[][] grid, int x, int y, Queue<int[]> Q, int countFreshOranges) { if (x &...


3

Type hints The parameters to your MazeSolver.__init__ should get type hints, particularly for things that don't have defaults. For instance, maze_path: str. Separate input You shouldn't be calling input from __init__. Just accept it as another parameter, and do the input and validation at a higher level. In-band logic Baking 'a' as a special condition ...


Top 50 recent answers are included