def threeSum(nums):
    res = []
    nums.sort()
    for i in range(len(nums)-2):
        if i > 0 and nums[i] == nums[i - 1]:
            continue
        left, right = i + 1, len(nums) - 1
        while left < right:
            summation = nums[i] + nums[left] + nums[right]
            if summation < 0:
                left += 1
            elif summation > 0:
                right -= 1
            else:
                res.append((nums[i], nums[left], nums[right]))
                while left < right and nums[left] == nums[left + 1]:
                    left += 1
                while left < right and nums[right] == nums[right - 1]:
                    right -= 1
                left += 1; right -= 1
    return res

if __name__ == '__main__':
    answer = threeSum([-1, 0, 1, 2, -1, -4])
    print(answer)