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,910 points
2,419 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,910 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
18,565 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,880 points
6,234 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
1,600 views
0 votes
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
274,673 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,058 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
3,479 views
0 votes
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,040 points
184,423 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