This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

72 wiersze
1.6 KiB

  1. import functools
  2. import types
  3. from collections import deque
  4. class fzset(frozenset):
  5. def __repr__(self):
  6. return '{%s}' % ', '.join(map(repr, self))
  7. def classify_bool(seq, pred):
  8. true_elems = []
  9. false_elems = []
  10. for elem in seq:
  11. if pred(elem):
  12. true_elems.append(elem)
  13. else:
  14. false_elems.append(elem)
  15. return true_elems, false_elems
  16. def classify(seq, key=None):
  17. d = {}
  18. for item in seq:
  19. k = key(item) if (key is not None) else item
  20. if k in d:
  21. d[k].append(item)
  22. else:
  23. d[k] = [item]
  24. return d
  25. def bfs(initial, expand):
  26. open_q = deque(list(initial))
  27. visited = set(open_q)
  28. while open_q:
  29. node = open_q.popleft()
  30. yield node
  31. for next_node in expand(node):
  32. if next_node not in visited:
  33. visited.add(next_node)
  34. open_q.append(next_node)
  35. try:
  36. STRING_TYPE = basestring
  37. except NameError: # Python 3
  38. STRING_TYPE = str
  39. Str = type(u'')
  40. def inline_args(f):
  41. # print '@@', f.__name__, type(f), isinstance(f, types.FunctionType), isinstance(f, types.TypeType), isinstance(f, types.BuiltinFunctionType)
  42. if isinstance(f, types.FunctionType):
  43. @functools.wraps(f)
  44. def _f_func(self, args):
  45. return f(self, *args)
  46. return _f_func
  47. elif isinstance(f, (type, types.BuiltinFunctionType)):
  48. @functools.wraps(f)
  49. def _f_builtin(_self, args):
  50. return f(*args)
  51. return _f_builtin
  52. else:
  53. @functools.wraps(f)
  54. def _f(self, args):
  55. return f.__func__(self, *args)
  56. return _f