The weight of the subset is the length of the value for each key.
Here is my attempt:
def nonDivisibleSubset(k, s):
remdict={}
result=[]
for i in range(len(s)):
rem=s[i]%k
if rem not in remdict:
remdict[rem]=[s[i]]
else:
remdict[rem].append(s[i])
b=dict(sorted(remdict.items(), key= lambda x: len(x[1]), reverse=True))
Input:
k=7
{2: [576, 338, 149, 702, 282, 436], 6: [496, 727, 209], 5: [278, 124], 4: [410, 718], 1: [771, 575]}
From this dictionary I want to append only the values of the keys 2,6,4 because 2+6!=7 and 2+4!=7 and 6+4!=7**