题目:四个数字可以生成多少个不相同且不重复的3位数,分别是什么?
1 a = '5843'
2 s = []
3 for i in a:
4 for j in a:
5 for k in a:
6 if i != j and j != k and i != k:
7 s.append(i+j+k)
8 print("total",len(s))
9 print(s)
执行结果如下:
total: 24
['584', '583', '548', '543', '538', '534', '854', '853', '845', '843', '835', '834', '458', '453', '485', '483', '435', '438', '358', '354', '385', '384', '345', '348']
==================================================================================
尊重原创,若需转载请注明出处:https://www.cnblogs.com/lizhe860/
==================================================================================