Graph weighted#11
Open
markreynoso wants to merge 22 commits into
Open
Conversation
…d tests, all passing.
…n and written test
nhuntwalker
reviewed
Dec 15, 2017
| ``` | ||
|
|
||
|
|
||
| ### Linkded List Class Usage |
| @@ -1,3 +1,6 @@ | |||
| graph_weighted | |||
| """Return a list of edges in graph.""" | ||
| edges = {} | ||
| for key in self._graph: | ||
| for i in self._graph[key]: |
There was a problem hiding this comment.
You should be using a better variable name than "i" here
| if val2 not in self._graph[val1]: | ||
| self._graph[val1][val2] = weight | ||
| elif val1 in self._graph and val2 not in self._graph: | ||
| self._graph[val2] = {} |
There was a problem hiding this comment.
You have a method whose only purpose is to add nodes. Why not just call that method?
| for key in self._graph: | ||
| for i in self._graph[key]: | ||
| if i == val: | ||
| del self._graph[key] |
There was a problem hiding this comment.
WHOA NOW! You're going to delete the whole node if the value you're looking for is found amongst its neighbors?!
| else: | ||
| raise ValueError('These edges do not exist.') | ||
| except KeyError: | ||
| raise ValueError('These edges do not exist.') |
|
|
||
| def has_node(self, val): | ||
| """Return true or false if node has value.""" | ||
| if val in self._graph: |
There was a problem hiding this comment.
The in operator returns a boolean value, so you could just
return val in self._graph| try: | ||
| for key in self._graph[val]: | ||
| neighbors.append(key) | ||
| return neighbors |
There was a problem hiding this comment.
You could just
return list(self._graph[val].keys())
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.