Guest User

Untitled

a guest
Oct 8th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. import collections
  2.  
  3.  
  4. def yoba(c, s, path=()):
  5.  
  6.     if not s:
  7.  
  8.         yield path
  9.  
  10.     if isinstance(c, str):
  11.  
  12.         c = collections.Counter(str.split(c))
  13.  
  14.     for word in sorted(c, key=len, reverse=True):
  15.  
  16.         head, tail = s[:len(word)], s[len(word):]
  17.         if sorted(word) == sorted(head):
  18.  
  19.             yield from yoba(c - collections.Counter(**{word: 1}), tail, path + ((word, head),))
  20.  
  21.  
  22. a, b = input(), input()
  23. print("\n".join(map(" ".join, zip(*next(yoba(a, b))))))
Advertisement
Add Comment
Please, Sign In to add comment