The Wayback Machine - https://web.archive.org/web/20200708033055/https://github.com/TheAlgorithms/Python/pull/2060
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create bipartite.py #2060

Open
wants to merge 8 commits into
base: master
from
Open

Create bipartite.py #2060

wants to merge 8 commits into from

Conversation

@jntushar
Copy link

jntushar commented Jun 2, 2020

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
graphs/bipartite.py Outdated Show resolved Hide resolved
graphs/bipartite.py Outdated Show resolved Hide resolved
graphs/bipartite.py Outdated Show resolved Hide resolved
jntushar and others added 3 commits Jun 2, 2020
Co-authored-by: Christian Clauss <[email protected]>
@jntushar
Copy link
Author

jntushar commented Jun 2, 2020

Code is working fine in my local machine...i don't understand why it is failing here

@cclauss
Copy link
Member

cclauss commented Jun 2, 2020

What input are you giving the program??

./graphs/bipartite.py:25: Explaination ==> Explanation
./graphs/bipartite.py:39: Explaination ==> Explanation
./graphs/bipartite.py:44:1: E302 expected 2 blank lines, found 1

@cclauss
Copy link
Member

cclauss commented Jun 2, 2020

What is n and what is m and why does the reader need to guess?

jntushar added 2 commits Jun 2, 2020
@jntushar
Copy link
Author

jntushar commented Jun 2, 2020

Now it can be merged.

@cclauss cclauss self-assigned this Jun 2, 2020
Co-authored-by: Christian Clauss <[email protected]>
@@ -35,6 +35,12 @@


def bipartite(partition: list, adjacent_edges: list) -> int:

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member
Suggested change
def bipartite(partition: list, adjacent_edges: list) -> int:
def bipartite(partition: list, adjacent_edges: list) -> bool:

It would be more Pythonic to return True or False instead of 0 or 1

step = 2
while queue:
node = queue.pop(0)
flag = 0

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member

What is flag measuring? Could we please have a more self documenting variable name? It should be a bool (True/False), not 0/1.

return 1


def colour(adjacent_edges): # Assigning alternative colours to the nodes of the graph

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member

Can we please have type hints and doctests for this function too?

queue = []
queue.append(0)
Comment on lines +59 to +60

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member
Suggested change
queue = []
queue.append(0)
queue = [0]
if step % 2 == 0:
partition[i] = 'B'
else:
partition[i] = 'W'
Comment on lines +71 to +74

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member
Suggested change
if step % 2 == 0:
partition[i] = 'B'
else:
partition[i] = 'W'
partition[i] = 'W' if step % 2 else 'B'
partition[i] = 'B'
else:
partition[i] = 'W'
if flag == 1:

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member
Suggested change
if flag == 1:
if flag:
partition[i] = 'W'
if flag == 1:
step += 1
return bipartite(partition, adjacent_edges) # return 1 if the graph is bipartite and 0 otherwise.

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member
Suggested change
return bipartite(partition, adjacent_edges) # return 1 if the graph is bipartite and 0 otherwise.
# return True if the graph is bipartite or False if it is not.
return bipartite(partition, adjacent_edges)

Lines must not be longer than 88 characters max as discussed in CONTRIBUTING.md.

user_input = sys.stdin.read()
data = list(map(int, user_input.split()))
Comment on lines +81 to +82

This comment has been minimized.

Copy link
@cclauss

cclauss Jun 7, 2020

Member
Suggested change
user_input = sys.stdin.read()
data = list(map(int, user_input.split()))
data = [int(x) for x in input("Enter integers separated by spaces").split()]
@cclauss
Copy link
Member

cclauss commented Jun 7, 2020

On your machine do python -m doctest -v pipartite.py to make sure that the doctests pass.
https://travis-ci.com/github/TheAlgorithms/Python/builds/170125057#L747

@stale
Copy link

stale bot commented Jul 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.