Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- def yoba(c, s, path=()):
- if not s:
- yield path
- if isinstance(c, str):
- c = collections.Counter(str.split(c))
- for word in sorted(c, key=len, reverse=True):
- head, tail = s[:len(word)], s[len(word):]
- if sorted(word) == sorted(head):
- yield from yoba(c - collections.Counter(**{word: 1}), tail, path + ((word, head),))
- a, b = input(), input()
- print("\n".join(map(" ".join, zip(*next(yoba(a, b))))))
Advertisement
Add Comment
Please, Sign In to add comment