我正在尝试制作一个输出字符串系列的程序,但是您可以选择它的开始位置,并且可以是任意数量的字符。例如,您可以说您想从bqrstw
开始,它会打印出来:
bqrstx
bqrsty
bqrstz
bqrsua
etc.
我一直在使用itertools,效果很好,但是我不知道如何知道从哪里开始。
import itertools
alphabet = "abcdefghijklmnopqrstuvwxyz"
print("Please input the length of the series.")
length = input("Length: ")
length = int(length)
def getString():
for s in itertools.product(alphabet, repeat = length):
yield ''.join(s)
print("What one do you want to start on?")
start = input("Start: ")
#use the start variable somewhere to make it start at any point
#currently this just prints it out starting at aaaa (if the length is 4)
for s in getString():
print(s)
我希望它输出从头开始的所有组合,包括头。
此帖子与此相似:Making string series in Python,但我需要一个起点。
您可以将开始传递给getString函数。