def pair_with_target_sum(nums: Sequence[int], target: int) -> Tuple[int, int]:
x = _pair_with_target_sum(nums, target, 0, len(nums) - 1)
return (nums[x[0]], nums[x[1]]) if x else x
Given that _pair_with_target_sum
may return None
or a Tuple[int, int]
, the above code works as expected. However, if I remove the parentheses around the tuple in the return statement, and when x
is None
, the code fails with TypeError: 'NoneType' object is not subscriptable
.
Why?.
Other relevant questions: