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 24, 2020 in Python by anonymous
• 8,880 points
516 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 24, 2020 by Gitika
• 65,930 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
7,414 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,780 points
2,439 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,230 points
527 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
123,402 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,251 views
0 votes
0 answers
+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,810 points
1,686 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,000 points
48,977 views