Median of Two Arrays#3554
Conversation
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
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: a6753050-1200-11eb-af4f-e3a6e0ba4ce0 |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 08572c10-1201-11eb-af4f-e3a6e0ba4ce0 |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 2f17a1b0-129f-11eb-af4f-e3a6e0ba4ce0 |
|
Please reformat this code with psf/black as discussed in CONTRIBUTING.md so that the tests below turn green. |
| m = findMedianArrays(n1, n2) | ||
| print(f'The median of two arrays is: {m}') |
There was a problem hiding this comment.
| m = findMedianArrays(n1, n2) | |
| print(f'The median of two arrays is: {m}') | |
| print(f'The median of two arrays is: {findMedianArrays(n1, n2)}') |
|
@cclauss , thanks for letting me know. I will format the the code accordingly :) |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 4613a080-12a4-11eb-8230-47bfa5f272e1 |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 8f00cbf0-12a5-11eb-8230-47bfa5f272e1 |
| list3 = nums1 + nums2 | ||
| list3 = nums1 + nums2 | ||
| list3.sort() | ||
| if divmod(len(list3), 2).[1] == 1: |
There was a problem hiding this comment.
| 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.
| list3 = nums1 + nums2 | ||
| list3 = nums1 + nums2 |
There was a problem hiding this comment.
| list3 = nums1 + nums2 | |
| list3 = nums1 + nums2 | |
| all_numbers = nums1 + nums2 |
Remove duplication and use a more self-documenting variable name.
| all_numbers = nums1 + nums2 | ||
| all_numbers.sort() |
There was a problem hiding this comment.
| all_numbers = nums1 + nums2 | |
| all_numbers.sort() | |
| all_numbers = sorted(nums1 + nums2) |
|
@cclauss |
cclauss
left a comment
There was a problem hiding this comment.
Awesome work! Thanks for your persistence.
* 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
* 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
* 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
* 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
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:
Checklist:
Fixes: #{$ISSUE_NO}.