import sys map lambda strip sys argv -1 split set def if not print joi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import sys
i=map(lambda x:x.strip(),sys.argv[1][1:-1].split(","))
r,g,s=[],1,set
def b(c,k):
if not k:
print "[%s]"%", ".join(r)
sys.exit()
for n in range(1,g+1):
for q in k:
if q[0].lower() in c[-n:]:
r.append(q)
b(q,list(s(k)-s([q])))
r.pop()
while 1:
for c in i:
r=[c]
b(c,list(s(i)-s([c])))
g+=1