-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_combo.py
32 lines (27 loc) · 884 Bytes
/
find_combo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from itertools import combinations
class find_combo:
def __init__(self, lst, num):
self.lst=lst
self.num=num
def combo(self):
return combinations(self.lst,self.num)
def sum_combo(self):
result={}
for item in self.combo():
if sum(item) not in result:
result[sum(item)]=[item]
else:
result[sum(item)].append(item)
return result
def diff_combo(self):
result={}
for item in self.combo():
if abs(item[0]-item[1]) not in result:
result[abs(item[0]-item[1])]=[item]
else:
result[abs(item[0]-item[1])].append(item)
return result
def show_me_result(self, num):
summy=self.sum_combo()
diffy=self.diff_combo()
return {'sum':summy.get(num),'diff':diffy.get(num)}