3.2.5.5 words in one sentence are randomly arranged, and 3.2.5.5 words are arranged in one sentence

Source: Internet
Author: User

3.2.5.5 words in one sentence are randomly arranged, and 3.2.5.5 words are arranged in one sentence

Now let's play a text game. Here is a sentence for you. Apart from the first character and the last character, the internal characters can be randomly queued. This game uses regular expressions to make it easier.

Example:

Import random text = 'Building Shenzhen into a global software center. This is the new beginning. '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 output is as follows:

Building Shenzhen into a global software center is a new start

The new starting point is to make the soft, deep, and full-blown products a ball in the middle.

Here, we mainly use the re. sub function to find grouping sentences, and place the intermediate characters in the repl function for computation. Then, we return and replace the entire string.






Cai junsheng QQ: 9073204 Shenzhen

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.