Now to do a text game, give you a word, this sentence in addition to the first and last character do not move, its internal characters can be randomly queued column. This game uses regular expression to do, it is relatively simple.
Example:
Import random Text = ' Build Shenzhen into a global software center It's a new start ' Def REPL (m): Inner_word = List (M.group (2)) Random.shuffle ( Inner_word) return M.group (1) + "". Join (Inner_word) + m.group (3) print (text) print (Re.sub (r "(\w) (\w+) (\w)", Repl, Text))
The resulting output is as follows:
To build Shenzhen into a global software center It's a new beginning.
The soft deep built all-in-one set the ball mean this opens the new is the beginning
Here is mainly through the function re.sub to find the grouping sentence, and then the middle of the character in the function repl to perform the operation, and then return to replace the entire string.
Cai Junsheng qq:9073204 Shenzhen
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
3.2.5.5 words in a sentence in random order