Program using re module that loops through the lines of a file or standard input where each line contains a single word and prints all words containing two adjacent vowels

0 votes
Example:

There is a list with ["eye", "ear", "waist", "neck"]

My output should be "ear" and "waist", since these words have two adjacent vowels in them.
Nov 24, 2020 in Python by S
• 120 points
2,556 views

1 answer to this question.

0 votes

Hey, @S,

you can have a look at the below given example:

s= "reading a book is great"
print(re.findall(r'\b\w[aeiou]{2}\w\b',s))

For both upper and lowercase vowels.

print(re.findall(r'\b\w[aeiouAEIOU]{2}\w\b',s))

You could use [A-Za-z] instead of \w, if you don't want a digit or _ exists before or after the vowels. Because \w also matches _ and digits.

print(re.findall(r'\b[A-Za-z][aeiouAEIOU]{2}[A-Za-z]\b',s))

Add case-insensitive modifier (?i) or re.IGNORECASE to do a case-insensitive match.

print(re.findall(r'(?i)\b[a-z][aeiou]{2}[a-z]\b',s))
answered Nov 24, 2020 by Gitika
• 65,770 points

Related Questions In Python

+4 votes
3 answers

Write a for loop that prints all elements of a list and their position in the list. a = [4,7,3,2,5,9]

Try using this question by list comprehension: a=[4,7,3,2,5,9] print([x for ...READ MORE

answered Dec 9, 2019 in Python by vinaykumar
• 200 points
34,894 views
+1 vote
1 answer
+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20, 2019 in Python by Sagar
• 130 points
1,194 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,454 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,108 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP