Hash table solution to twoSum
First some stylistic points


nums_d.setdefault(nums[i], []).append(i)

The setdefault is unnecessary here, you can assign a list normally

nums_d[nums[i]] = [i]

When you need both the index and the element use enumerate see PEP279


nums_d = {}
for i in range(len(nums)):
    nums_d.setdefault(nums[i], []).append(i)



nums_d = {}
for i, e  in enumerate(nums):
    nums_d[e] = [i]

Use comprehension when possible (They use the C style looping and is considered to be faster)

nums_d = { e: [i] for i, e  in enumerate(nums) }



Hint

You loop over nums twice, but this can be done in one loop! To make it O(n)

Whenever you visit a new element in nums ->

Check if it's sum complement is in nums_d, else add the target - element to the dictionary with the index as value t - e : i


   nums_d = {}
for i, e in enumerate(nums):
    if e in nums_d:
        return [nums_d[e], i]
    nums_d[target - e] = i