import sys map lambda strip sys argv -1 split def cs if not cs print j

 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=[],1
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(set(cs)-set([c1])))
r.pop()
while 1:
for c in i:
r=[c]
b(c,list(set(i)-set([c])))
g+=1