import sys map lambda strip sys argv -1 split set def cs if not cs pri

 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,cs):
if not cs:
print "[%s]"%", ".join(r)
sys.exit()
for n in range(1,g+1):
for c1 in cs:
if c1[0].lower() in c[-n:]:
r.append(c1)
b(c1,list(s(cs)-s([c1])))
r.pop()
while 1:
for c in i:
r=[c]
b(c,list(s(i)-s([c])))
g+=1