fork download
  1. def _allSame(xs):
  2. """allSame([x]) -> x0 == x1 == .. == xn"""
  3.  
  4. #""" ## for short xs:
  5. xs = tuple(xs)
  6. return not xs or xs.count(xs[0]) == len(xs)
  7. #"""
  8. """ ## for looong xs:
  9. xs = iter(xs)
  10.  
  11. try:
  12. p = next(xs)
  13.  
  14. except StopIteration:
  15. return True
  16.  
  17. return all(p == x for x in xs)
  18. """
  19.  
  20. def equivalent(*iterables, keyfunc=lambda x:x):
  21. return all(map(_allSame, zip(*map(keyfunc, iterables))))
  22.  
  23. ###########################
  24.  
  25. from functools import partial
  26.  
  27. isVowel = set('AЕЁИОУЫЭЮЯаеёиоуыэюя').__contains__
  28.  
  29. print('equivalent "ололо", "ороро" ->',
  30. equivalent("ололо", "ороро", keyfunc=partial(map, isVowel))
  31. # >>> True
  32. )
  33. print('equivalent "ололо", "ороро", "битард" ->',
  34. equivalent("ололо", "ороро", "битард", keyfunc=partial(map, isVowel))
  35. # >>> False
  36. )
  37.  
  38. from itertools import groupby
  39.  
  40. def deltaCV(cs):
  41. for c, _ in groupby(map(isVowel, cs)):
  42. yield c
  43.  
  44. print('equivalent "ололо", "ороро", "ооооллоло" ->',
  45. equivalent("ололо", "ороро", "ооооллоло", keyfunc=deltaCV)
  46. # >>> True
  47. )
  48. print('equivalent "ололо", "ороро", "трооооллоло" ->',
  49. equivalent("ололо", "ороро", "трооооллоло", keyfunc=deltaCV)
  50. # >>> False
  51. )
Success #stdin #stdout 0.03s 9440KB
stdin
Standard input is empty
stdout
equivalent "ололо", "ороро" -> True
equivalent "ололо", "ороро", "битард" -> False
equivalent "ололо", "ороро", "ооооллоло" -> True
equivalent "ололо", "ороро", "трооооллоло" -> False