我正在制作一个猜测密码的小程序
我制作这个程序只是为了学习,我想通过制作一个真正有意义的程序来提高我的python技能
例如:
using_characts = "abcdefghijklmnopqrstuvwxyz" # I have other characters in my alphabetic system
我想做的是这样的:
for char in myCharacters:
print(char)
for char_1 in myCharacters:
print(char + char_1)
for char_2 in myCharacters:
print(char + char_1 + char_2)
...etc
这使得该方法非动态,同时也很难实现。 输出应如下所示:
a
b
c
d
e
f
..etc
aa
ab
ac
..etc
ba
bb
bc
..etc
所以,其他答案给了你可能会工作的代码,但我想解释一个通用的方法。此算法使用堆栈跟踪下一个需要生成的内容,并继续生成,直到达到指定的最大长度
你可以用
print("\n".join(generate_all_strings("abc", maxlen=5)))
试试您可以使用^{} ,但您确实应该用一个小数字来限制自己。为更高的数字生成笛卡尔乘积可能需要很长时间:
给你,这会有用的。如果你想让我解释任何部分,请告诉我
相关问题 更多 >
编程相关推荐