Skip to main content
added 12 characters in body
Source Link
toolic
  • 15.7k
  • 5
  • 29
  • 216

The previous answer addresses your main concern about complexity. This will address one of the now-deleted comments on the question regarding functionality.

Portability

The function that was posted must be part of a class which was not posted. The code can't be run as-is due to the presence of the self keyword. I removed self and added an example function call:

def findMedianSortedArrays(nums1, nums2):
    nums = nums1 + nums2
    nums.sort
    if len(nums) % 2 == 0:
        return (nums[(len(nums) / 2) - 1] + nums[len(nums) / 2]) / 2.0
    else:
        return nums[len(nums) // 2] 

print(findMedianSortedArrays([6,4,5], [2,3,1]))

When I run the code on Python version 2.7, I get the expected answer:

3.5

However, when I run the code on Python version 3.7, I get an error:

TypeError: list indices must be integers or slices, not float

Since Python 2.7 is deprecated, I suggest modifying the code to run on newer 3.x versions as well.

Naming

The PEP 8 style guide recommends using snake_case for function names:

find_median_sorted_arrays

The previous answer addresses your main concern about complexity. This will address one of the comments on the question regarding functionality.

Portability

The function that was posted must be part of a class which was not posted. The code can't be run as-is due to the presence of the self keyword. I removed self and added an example function call:

def findMedianSortedArrays(nums1, nums2):
    nums = nums1 + nums2
    nums.sort
    if len(nums) % 2 == 0:
        return (nums[(len(nums) / 2) - 1] + nums[len(nums) / 2]) / 2.0
    else:
        return nums[len(nums) // 2] 

print(findMedianSortedArrays([6,4,5], [2,3,1]))

When I run the code on Python version 2.7, I get the expected answer:

3.5

However, when I run the code on Python version 3.7, I get an error:

TypeError: list indices must be integers or slices, not float

Since Python 2.7 is deprecated, I suggest modifying the code to run on newer 3.x versions as well.

Naming

The PEP 8 style guide recommends using snake_case for function names:

find_median_sorted_arrays

The previous answer addresses your main concern about complexity. This will address one of the now-deleted comments on the question regarding functionality.

Portability

The function that was posted must be part of a class which was not posted. The code can't be run as-is due to the presence of the self keyword. I removed self and added an example function call:

def findMedianSortedArrays(nums1, nums2):
    nums = nums1 + nums2
    nums.sort
    if len(nums) % 2 == 0:
        return (nums[(len(nums) / 2) - 1] + nums[len(nums) / 2]) / 2.0
    else:
        return nums[len(nums) // 2] 

print(findMedianSortedArrays([6,4,5], [2,3,1]))

When I run the code on Python version 2.7, I get the expected answer:

3.5

However, when I run the code on Python version 3.7, I get an error:

TypeError: list indices must be integers or slices, not float

Since Python 2.7 is deprecated, I suggest modifying the code to run on newer 3.x versions as well.

Naming

The PEP 8 style guide recommends using snake_case for function names:

find_median_sorted_arrays
added 3 characters in body
Source Link
toolic
  • 15.7k
  • 5
  • 29
  • 216

The otherprevious answer addresses your main concern about complexity. This will address one of the comments on the question regarding functionality.

Portability

The function that was posted must be part of a class which was not posted. The code can't be run as-is due to the presence of the self keyword. I removed self and added an example function call:

def findMedianSortedArrays(nums1, nums2):
    nums = nums1 + nums2
    nums.sort
    if len(nums) % 2 == 0:
        return (nums[(len(nums) / 2) - 1] + nums[len(nums) / 2]) / 2.0
    else:
        return nums[len(nums) // 2] 

print(findMedianSortedArrays([1[6,24,3]5], [4[2,53,6]1]))

When I run the code on Python version 2.7, I get the expected answer:

3.5

However, when I run the code on Python version 3.7, I get an error:

TypeError: list indices must be integers or slices, not float

Since Python 2.7 is deprecated, I suggest modifying the code to run on newer 3.x versions as well.

Naming

The PEP 8 style guide recommends using snake_case for function names:

find_median_sorted_arrays

The other answer addresses your main concern about complexity. This will address one of the comments on the question regarding functionality.

Portability

The function that was posted must be part of a class which was not posted. The code can't be run as-is due to the presence of the self keyword. I removed self and added an example function call:

def findMedianSortedArrays(nums1, nums2):
    nums = nums1 + nums2
    nums.sort
    if len(nums) % 2 == 0:
        return (nums[(len(nums) / 2) - 1] + nums[len(nums) / 2]) / 2.0
    else:
        return nums[len(nums) // 2] 

print(findMedianSortedArrays([1,2,3], [4,5,6]))

When I run the code on Python version 2.7, I get the expected answer:

3.5

However, when I run the code on Python version 3.7, I get an error:

TypeError: list indices must be integers or slices, not float

Since Python 2.7 is deprecated, I suggest modifying the code to run on newer 3.x versions as well.

Naming

The PEP 8 style guide recommends using snake_case for function names:

find_median_sorted_arrays

The previous answer addresses your main concern about complexity. This will address one of the comments on the question regarding functionality.

Portability

The function that was posted must be part of a class which was not posted. The code can't be run as-is due to the presence of the self keyword. I removed self and added an example function call:

def findMedianSortedArrays(nums1, nums2):
    nums = nums1 + nums2
    nums.sort
    if len(nums) % 2 == 0:
        return (nums[(len(nums) / 2) - 1] + nums[len(nums) / 2]) / 2.0
    else:
        return nums[len(nums) // 2] 

print(findMedianSortedArrays([6,4,5], [2,3,1]))

When I run the code on Python version 2.7, I get the expected answer:

3.5

However, when I run the code on Python version 3.7, I get an error:

TypeError: list indices must be integers or slices, not float

Since Python 2.7 is deprecated, I suggest modifying the code to run on newer 3.x versions as well.

Naming

The PEP 8 style guide recommends using snake_case for function names:

find_median_sorted_arrays
Source Link
toolic
  • 15.7k
  • 5
  • 29
  • 216

The other answer addresses your main concern about complexity. This will address one of the comments on the question regarding functionality.

Portability

The function that was posted must be part of a class which was not posted. The code can't be run as-is due to the presence of the self keyword. I removed self and added an example function call:

def findMedianSortedArrays(nums1, nums2):
    nums = nums1 + nums2
    nums.sort
    if len(nums) % 2 == 0:
        return (nums[(len(nums) / 2) - 1] + nums[len(nums) / 2]) / 2.0
    else:
        return nums[len(nums) // 2] 

print(findMedianSortedArrays([1,2,3], [4,5,6]))

When I run the code on Python version 2.7, I get the expected answer:

3.5

However, when I run the code on Python version 3.7, I get an error:

TypeError: list indices must be integers or slices, not float

Since Python 2.7 is deprecated, I suggest modifying the code to run on newer 3.x versions as well.

Naming

The PEP 8 style guide recommends using snake_case for function names:

find_median_sorted_arrays