w3resource logo


Python Exercises

Python: Find all adverbs and their positions in a given sentence

Python Regular Expression: Exercise-46 with Solution

Write a Python program to find all adverbs and their positions in a given sentence.

Sample text :

"Clearly, he has no excuse for such behavior."

Sample Solution :-

Python Code :

import re
text = "Clearly, he has no excuse for such behavior."
for m in re.finditer(r"\w+ly", text):
    print('%d-%d: %s' % (m.start(), m.end(), m.group(0)))

Python Code Editor:

import re
text = "Clearly, he has no excuse for such behavior."
for m in re.finditer(r"\w+ly", text):
    print('%d-%d: %s' % (m.start(), m.end(), m.group(0)))

Improve this sample solution and post your code through Disqus



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program