This is not a solution, but it should give you some ideas…

Python 2 code

```
>>> from itertools import combinations as ncr
>>> class Solution:
def __init__(self, nums, target):
self.nums = nums
self.target = target
def two_nums(self):
combs = ncr(self.nums, 2)
return filter(lambda x: reduce(lambda a, b: a + b == self.target, x), combs)
>>> solve = Solution([2, 5, 8, 11, 15], 19)
>>> solve.two_nums()
[(8, 11)]
>>>
```

It’s likely overkill and can be simplified. See what you can glean.

Note: In Python 3 `reduce`

is in the `functools`

module.

Further exploration

```
>>> class Solution:
def __init__(self, nums, target):
self.nums = nums
self.target = target
def indices(self, x):
return [self.nums.index(i) for i in x[0]]
def two_nums(self):
combs = ncr(self.nums, 2)
return self.indices(filter(lambda x: reduce(lambda a, b: a + b == self.target, x), combs))
>>> solve = Solution([2, 5, 8, 11, 15], 19)
>>> solve.two_nums()
[2, 3]
>>>
```

Edit

Got rid of `reduce`

.

```
>>> class Solution:
def __init__(self, nums, target):
self.nums = nums
self.target = target
def indices(self, x):
return [self.nums.index(i) for i in x[0]]
def match(self, x):
return x[0] + x[1] == self.target
def two_nums(self):
combs = ncr(self.nums, 2)
return self.indices(filter(self.match, combs))
>>> solve = Solution([2, 5, 8, 11, 15], 19)
>>> solve.two_nums()
[2, 3]
>>>
```

```
>>> Solution([2, 5, 8, 11, 15], 19).two_nums()
[2, 3]
>>>
```

Edit

BTW, still haven’t followed the link so this is seat of the pants stuff.

Edit

Got rid of the comprehension…

```
>>> class Solution:
def __init__(self, nums, target):
self.nums = nums
self.target = target
def indices(self, x):
return [self.nums.index(x[0]), self.nums.index(x[1])]
def match(self, x):
return x[0] + x[1] == self.target
def two_nums(self):
combs = ncr(self.nums, 2)
return self.indices(filter(self.match, combs)[0])
>>> Solution([2, 5, 8, 11, 15], 19).two_nums()
[2, 3]
>>>
```