例如,我有这样一个文本:This is a good reason to stop.
(字数总是大于5)
words = ['This', 'is', 'a', 'good', 'reason', 'to', 'stop']
flashcards_count = ciel(len(word) / 3)
我想要的结果是:
[
'This __ a good ______ to ____.'
'____ is a ____ reason __ stop.'
'This is _ good reason to stop.'
]
你可能注意到了,我尽量避免按顺序放空格,除非是最后一张抽认卡。你知道吗
为此,我将words
洗牌并将其分块为3,以生成每个抽认卡,但结果可能是这样的:
[
'This is a ____ ______ __ stop.'
'____ __ _ good reason to stop.'
'This is a good reason to ____.'
]
您可以使用“随机”模块对字符串列表进行无序排列,然后在中间添加一个空格:
如果您还想洗牌非字符串,请看一下Shuffling a list of objects。你知道吗
相关问题 更多 >
编程相关推荐