fork download
  1. def charsWithCounter(s):
  2. res = {}
  3. for c in s:
  4. res[c] = res.get(c, 0) + 1
  5. return res
  6.  
  7. def isValid(str_source, str_to_compare):
  8. if list(set(str_to_compare) - set(str_source)):
  9. return False
  10.  
  11. dct_source = charsWithCounter(str_source)
  12. dct_to_compare = charsWithCounter(str_to_compare)
  13.  
  14. for key in dct_to_compare.keys():
  15. if key in dct_source and dct_to_compare[key] > dct_source[key]:
  16. return False
  17. return True
  18.  
  19.  
  20. dct = {
  21. "DENOOPRSU": ["PONDEROUS", "PONDEROUSZ", "PONDEROU S", "SPONSORED", "ONEROUS", "USURPER", "ABC", " ", "OOO", "O"],
  22. "CDEIORSVY": ["DISCOVERY"]
  23. }
  24.  
  25. for k, v in dct.items():
  26. for s in v:
  27. print("'{}' --> '{}' : {}".format(k, s, str(isValid(k, s))))
Success #stdin #stdout 0.03s 9644KB
stdin
Standard input is empty
stdout
'DENOOPRSU' --> 'PONDEROUS' : True
'DENOOPRSU' --> 'PONDEROUSZ' : False
'DENOOPRSU' --> 'PONDEROU S' : False
'DENOOPRSU' --> 'SPONSORED' : False
'DENOOPRSU' --> 'ONEROUS' : True
'DENOOPRSU' --> 'USURPER' : False
'DENOOPRSU' --> 'ABC' : False
'DENOOPRSU' --> ' ' : False
'DENOOPRSU' --> 'OOO' : False
'DENOOPRSU' --> 'O' : True
'CDEIORSVY' --> 'DISCOVERY' : True