# 1,2,3,4,5可以组成多少个三位数并列举出来
# 总体思想,三位数, 遍历3次, 去除各个位数上相等的数。余下的就是
def threeNum(l):
lists = []
for i in l:
for j in l:
for k in l:
if i != j and i != k and j != k:
num = str(i)+str(j)+str(k)
lists.append(num)
return set(lists) # l中有重复元素时候去重
l = [1, 2, 3, 4, 5, 5, 3, 2, 1]
print(threeNum(l))
网友评论