Skip to content

Conversation

@anneCoder1805
Copy link
Contributor

@anneCoder1805 anneCoder1805 commented Oct 19, 2020

This code finds the median of two arrays (which may or may not be sorted initially).
Example:
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is : 4

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}.

This code finds the median of two arrays (which may or may not be sorted initially).
Example: 
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is :  4
@TravisBuddy
Copy link

Travis tests have failed

Hey @anneCoder1805,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: a6753050-1200-11eb-af4f-e3a6e0ba4ce0

@TravisBuddy
Copy link

Travis tests have failed

Hey @anneCoder1805,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 08572c10-1201-11eb-af4f-e3a6e0ba4ce0

@TravisBuddy
Copy link

Travis tests have failed

Hey @anneCoder1805,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 2f17a1b0-129f-11eb-af4f-e3a6e0ba4ce0

@cclauss
Copy link
Member

cclauss commented Oct 20, 2020

Please reformat this code with psf/black as discussed in CONTRIBUTING.md so that the tests below turn green.

Comment on lines 21 to 22
m = findMedianArrays(n1, n2)
print(f'The median of two arrays is: {m}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m = findMedianArrays(n1, n2)
print(f'The median of two arrays is: {m}')
print(f'The median of two arrays is: {findMedianArrays(n1, n2)}')

@anneCoder1805
Copy link
Contributor Author

@cclauss , thanks for letting me know. I will format the the code accordingly :)

@TravisBuddy
Copy link

Travis tests have failed

Hey @anneCoder1805,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 4613a080-12a4-11eb-8230-47bfa5f272e1

@TravisBuddy
Copy link

Travis tests have failed

Hey @anneCoder1805,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 8f00cbf0-12a5-11eb-8230-47bfa5f272e1

list3 = nums1 + nums2
list3 = nums1 + nums2
list3.sort()
if divmod(len(list3), 2).[1] == 1:
Copy link
Member

@cclauss cclauss Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if divmod(len(list3), 2).[1] == 1:
div, mod = divmod(len(list3), 2)
if mod == 1:

Then replace a with div which is already calculated.

Comment on lines 3 to 4
list3 = nums1 + nums2
list3 = nums1 + nums2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
list3 = nums1 + nums2
list3 = nums1 + nums2
all_numbers = nums1 + nums2

Remove duplication and use a more self-documenting variable name.

Comment on lines 3 to 4
all_numbers = nums1 + nums2
all_numbers.sort()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
all_numbers = nums1 + nums2
all_numbers.sort()
all_numbers = sorted(nums1 + nums2)

@anneCoder1805 anneCoder1805 requested a review from cclauss October 20, 2020 09:29
@anneCoder1805
Copy link
Contributor Author

@cclauss
Thanks a lot for helping me out wherever I got stuck. This is really a great learning experience for me. I am really grateful to you for this help.

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! Thanks for your persistence.

@cclauss cclauss added the hacktoberfest-accepted Accepted to be counted towards Hacktoberfest label Oct 20, 2020
@cclauss cclauss merged commit 7423302 into TheAlgorithms:master Oct 20, 2020
@cclauss
Copy link
Member

cclauss commented Oct 20, 2020

stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Create medianOf TwoArrays.py

This code finds the median of two arrays (which may or may not be sorted initially).
Example: 
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is :  4

* Rename medianOf TwoArrays.py to median_of _two_arrays.py

* Rename median_of _two_arrays.py to median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py
peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this pull request Apr 1, 2021
* Create medianOf TwoArrays.py

This code finds the median of two arrays (which may or may not be sorted initially).
Example: 
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is :  4

* Rename medianOf TwoArrays.py to median_of _two_arrays.py

* Rename median_of _two_arrays.py to median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* Create medianOf TwoArrays.py

This code finds the median of two arrays (which may or may not be sorted initially).
Example: 
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is :  4

* Rename medianOf TwoArrays.py to median_of _two_arrays.py

* Rename median_of _two_arrays.py to median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
* Create medianOf TwoArrays.py

This code finds the median of two arrays (which may or may not be sorted initially).
Example: 
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is :  4

* Rename medianOf TwoArrays.py to median_of _two_arrays.py

* Rename median_of _two_arrays.py to median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

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

Labels

hacktoberfest-accepted Accepted to be counted towards Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants