Share my 5 lines of Python solution
From the previous question Subsets I, the iterate solution is \n\n    def subsets(self, nums):\n        res = [[]]\n        nums.sort()\n        for num in nums
From the previous question Subsets I, the iterate solution is \n\n    def subsets(self, nums):\n        res = [[]]\n        nums.sort()\n        for num in nums: \n            res += [ i + [num] for i in res]\n        return res\n\nFor every number in nums, we add it to every i in res. Ex. [[]], we add [] + [1] to res. The new res is [ [], [1] ]. Then add [] + [2] and [1] + [2], the new res is [[],[1],[2],[1,2]]. \n\nTo void the duplicate, we check if i + [num] is already in res. So the iterate solution for Subsets II is: \n\n    def subsetsWithDup(self, nums):\n        res = [[]]\n        nums.sort()\n        for num in nums: \n            res += [ i + [num] for i in res if i + [num] not in res]\n        return res
['Python']