昨天看书想到一个问题,在1-9中选n个数出来,组成不重复的组合一个有多少中组合方式。下面的例子是选三个数

#!/usr/bin/python2
import itertools

def get_list(item = 2):
irange = range(1,10,1)
ilist = list(itertools.permutations(irange,item))
nlist = []
for l in ilist:
nlist.append(‘’.join(str(e) for e in l))
return nlist

def test():
l = get_list(item = 3)
print “Found %d, there are:\n\t%s” % (len(l),l)

if __name__ == ‘__main__‘:
test()