3.2.5.6 Find all the adjectives in an English sentence

Source: Internet
Author: User

3.2.5.6Find all the adjectives in an English sentence

If you want to find all occurrences of a matching character in a text, you need to use the findall () function instead of the search () function . For example, if an English writer wants to find all the adjectives in an English language, he or she will use findall () to achieve this function.

Example:

Text = "He was carefully disguised but captured quickly by police."

Print (text)

Print (Re.findall (r "\w+ly", text))

The resulting output is as follows:

He was carefully disguised and captured quickly by police.

[' carefully ', ' quickly ']

In this case, it is to find out all the words with the word " ly ", and from the result it is the word with the end of Ly, which has been achieved.

3.2.5.7Find all adjectives and locations in English sentences

If you want to see not just all the adjectives that appear in the English sentence, but also the location, then using the findall () function does not reach this goal, and you need to use the finditer () function to find it, so the match Object brings back all the information, not just the string. To continue on to an example, suppose that a writer wants to find out all the adjectives used and mark out the places where he or she will do the work?

Example:

Text = "He was carefully disguised but captured quickly by police."

Print (text)

For M in Re.finditer (r "\w+ly", text):

Print ('%02d-%02d:%s '% (M.start (), M.end (), M.group (0)))

The resulting output is as follows:

He was carefully disguised and captured quickly by police.

07-16:carefully

40-47:quickly




Cai Junsheng No.: Shenzhencai Shenzhen

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

3.2.5.6 Find all the adjectives in an English sentence

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.