Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wanderingstan/4b8ae84dd77eadf716b012f2a5e74790 to your computer and use it in GitHub Desktop.
Save wanderingstan/4b8ae84dd77eadf716b012f2a5e74790 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BoManev
Copy link

BoManev commented Jan 6, 2024

The set has the following signature for the __sub__ method:

  • def __sub__(self, __value: AbstractSet[_T | None]) -> set[_T]:
    • This creates an intermediate set.

We can instead use an iterator directly from the visited list

  • difference(*s: Iterable[Any]) -> set[str]
  • stack.extend(graph[vertex].difference(visited))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment