':type nums: List[int]
:type target: int
:rtype: List[List[int]]'

def fourSum(self, nums, target):

    (nums, result, lookup) = (sorted(nums), [], collections.defaultdict(list))
    for i in xrange(0, (len(nums) - 1)):
        for j in xrange((i + 1), len(nums)):
            is_duplicated = False
            for [x, y] in lookup[(nums[i] + nums[j])]:
                if (nums[x] == nums[i]):
                    is_duplicated = True
                    break
            if (not is_duplicated):
                lookup[(nums[i] + nums[j])].append([i, j])
    ans = {}
    for c in xrange(2, len(nums)):
        for d in xrange((c + 1), len(nums)):
            if (((target - nums[c]) - nums[d]) in lookup):
                for [a, b] in lookup[((target - nums[c]) - nums[d])]:
                    if (b < c):
                        quad = [nums[a], nums[b], nums[c], nums[d]]
                        quad_hash = '    '.join(str(quad))
                        if (quad_hash not in ans):
                            ans[quad_hash] = True
                            result.append(quad)
    return result
