Advertisement
STANAANDREY

inter + reunion digits py

Jan 16th, 2023
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. from functools import reduce
  2.  
  3. def getDigsFromNr(nr):
  4.     ans = set()
  5.     if nr != 0:
  6.         ans.add(nr % 10)
  7.         ans.update(getDigsFromNr(nr // 10))
  8.     return ans
  9.  
  10. def getReunionAndInter(nrSet):
  11.     def unionRed(acc, elem):
  12.         return acc.union(getDigsFromNr(elem))
  13.     def interRed(acc, elem):
  14.         return acc.intersection(getDigsFromNr(elem))
  15.     union = reduce(unionRed, nrSet, set())
  16.     inter = reduce(interRed, nrSet, getDigsFromNr(list(nrSet)[0]))
  17.     return union, inter
  18.  
  19. print(getReunionAndInter({1234, 123, 127}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement