import itertools as itrs
s = "abc"
rslt = ','.join((','.join((''.join(tlp)for tlp in itrs.combinations(s,r)))
for r in range(1,len(s)+1)))
print(rslt)
'a,b,c,ab,ac,bc,abc'
简洁些~
from itertools import chain, combinations as combs
chn_itr = chain.from_iterable
s = "abc"
print([''.join(x)for x in chn_itr(combs(s,r)for r in range(1,len(s)+1))])
考虑算法实现吧,穷举的js
直接用组合算法吧~
python3
简洁些~