该random
模块是一个很棒的模块,它将对此有所帮助。
我使用该string
模块删除所有标点符号。
import random
import string
sentence_one = raw_input('Enter the first sentence! ').translate(None, string.punctuation)
sentence_two = raw_input('Enter the second sentence! ').translate(None, string.punctuation)
mylist1 = sentence_one.split()
mylist2 = sentence_two.split()
mylist3 = mylist1 + mylist2
random.shuffle(mylist3)
randomsentence = ' '.join(mylist3)
print randomsentence
运行时:
Enter the first sentence! one, two, three
Enter the second sentence! four! five! six!
three two four six one five # Well it could be anything really, this is randomised.