```python
def middle(nums1,nums2): len1=len(nums1) len2=len(nums2) ret=0 if len1 == 0: if len2 % 2 == 0: sum = nums2[len2/2] + nums2[len2/2 - 1] if sum % 2 == 0: ret = sum / 2 else: ret = sum / 2.0 else: ret=nums2[len2/2] elif len2 == 0: if len1 % 2 == 0: sum = nums1[len1/2] + nums1[len1/2 - 1] if sum % 2 == 0: ret = sum / 2 else: ret = sum / 2.0 else: ret=nums1[len1/2] else: l1=0; l2=0; ls=[] while l1 < len1 or l2 < len2: if l1 == len1: if l2 < len2: ls += nums2[l2:] l2 = len2 elif l2 == len2: if l1 < len1: ls += nums1[l1:] l1 = len1 else: if nums1[l1] < nums2[l2]: ls.append(nums1[l1]) l1 +=1 else: ls.append(nums2[l2]) l2 +=1 if (len1 + len2)%2 == 0: sum = ls[(len1+len2)/2] + ls[(len1+len2)/2 - 1] if sum % 2 == 0: ret = sum / 2 else: ret = sum / 2.0 else: ret = ls[(len1+len2)/2] return ret
#middle([],[1]) #middle([2,3],[]) #middle([1,3,5],[4,5])