How to find the occurrences of any word with more than two vowels in a file using regex

0 votes

I'm having trouble figuring out how to find all words that have 2 or more vowels in them. So far this is what I have but when i run it, it don't give me any output. I appreciate the help.

import re

def main():

in_f = open("jobs-061505.txt", "r")
read = in_f.read()
in_f.close()
for word in read:
    re.findall(r"\b[aAeEiIoOuU]*", read)
    in_f = open("twoVoweledWordList.txt", "w")
    in_f.write(word)
    in_f.close()

print (word)
main()
Nov 25, 2020 in Python by anonymous
• 8,870 points
2,770 views

1 answer to this question.

0 votes
for word in read:  <--- iterating over chars in "read"!
    re.findall(r"\b[aAeEiIoOuU]*", read)  <-- using read again, discarding result

your iteration and pattern usage do not align. Plus, you don't use the result.

Consider processing the file line by line etc.

twovowels=re.compile(r".*[aeiou].*[aeiou].*", re.I)
nonword=re.compile(r"\W+", re.U)
file = open("filename")
for line in file:
    for word in nonword.split(line):
        if twovowels.match(word): print word
file.close()
answered Nov 25, 2020 by Gitika
• 65,770 points

Related Questions In Python

0 votes
1 answer

How to find the value of a row in a csv file in python?

If you want to find the value ...READ MORE

answered May 20, 2019 in Python by Sanam
19,274 views
0 votes
1 answer

How to find the value of a row in a csv file in python and print column and row of that value ?

Hello @Khanhh , Use panda to find the value of ...READ MORE

answered Oct 15, 2020 in Python by Niroj
• 82,840 points
6,824 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29, 2019 in Python by rajesh
• 1,270 points
2,186 views
+1 vote
1 answer

How to find the index of a particular value in a dataframe?

First, use the dataframe to match the ...READ MORE

answered Apr 8, 2019 in Python by Esha
281,992 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,478 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,141 views
+1 vote
4 answers

how to sort a list of numbers without using built-in functions like min, max or any other function?

Yes it is possible. You can refer ...READ MORE

answered Jun 27, 2019 in Python by Arvind
• 3,050 points
188,652 views
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