Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from functools import reduce
- def getDigsFromNr(nr):
- ans = set()
- if nr != 0:
- ans.add(nr % 10)
- ans.update(getDigsFromNr(nr // 10))
- return ans
- def getReunionAndInter(nrSet):
- def unionRed(acc, elem):
- return acc.union(getDigsFromNr(elem))
- def interRed(acc, elem):
- return acc.intersection(getDigsFromNr(elem))
- union = reduce(unionRed, nrSet, set())
- inter = reduce(interRed, nrSet, getDigsFromNr(list(nrSet)[0]))
- return union, inter
- print(getReunionAndInter({1234, 123, 127}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement