用指定数字制作所有数字,Python
在Python中,我想获得所有n位数字,数字1至n(n< 10,每个n位数字)。我怎么能?
可以做类似的事情吗? 谢谢
in python, I want to get all n-digit numbers with digits 1 to n (n <10, each exactly once). How can I ??
Can similar things be done?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
itertools.permutations()
获取每个数字的数字,然后使用map()
与str()
和int()< / code>将生成的数字转换为所需数字:
此输出(仅显示前三行 /最后三行):
You can use
itertools.permutations()
to get the digits of each number, and then usemap()
withstr()
andint()
to turn the generated digits into the desired numbers:This outputs (only first three / last three lines shown):
只需使用
itertools.permutations
输出:
Just use
itertools.permutations
Output: