forked from kumaya/python-programs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitertoolsUseCase.py
More file actions
Latest commit
14 lines (10 loc) · 471 Bytes
/
Copy pathitertoolsUseCase.py
File metadata and controls
14 lines (10 loc) · 471 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Given an randomly arranged array. Find all the subsets (of any size) in the array so that
# the sum of elements in subset is exactly divisible by 7
# This example illustrates the basic usecase of itertools library
fromitertoolsimportcombinations, chain
deftest(inp):
len_inp=len(inp)
var=chain.from_iterable(combinations(inp, n) forninrange(len_inp+1))
returnvar
inp= [1,2,3,4,5]
printfilter((lambdax: len(x)>0andsum(x)%7==0), list(test(inp)))