【题目】
从1,2,3,4四个数字中组成互不相同且不重复的三位数,要求全部列出
【题目分析】
用列表生成式一步到位
【解答】
1 #!/Users/minutesheep/.pyenv/shims/python
2 # -*- coding: utf-8 -*-
3
4 ans = [i*100+j*10+k for i in range(1, 5) for j in range(1, 5)
5 ¦ for k in range(1, 5) if i != j and i != k and j != k]
6 print(ans)
[123, 124, 132, 134, 142, 143, 213, 214, 231, 234, 241, 243, 312, 314, 321, 324, 341, 342, 412, 413, 421, 423, 431, 432]
原文出处:https://www.cnblogs.com/minutesheep/p/10386942.html
来源:oschina
链接:https://my.oschina.net/u/4345058/blog/3269539