例如,我有这样的文字: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 ____.'
]
答案 0 :(得分:0)
您可以使用随机模块来混洗字符串列表,然后将它们与空格连接起来:
import random
list = ['This', 'is', 'a', 'good', 'reason', 'to', 'make', 'stop']
random.shuffle(list)
print " ".join(list)
如果您想要将非字符串随机播放,请查看Shuffling a list of objects。