Answer to Question #235908 in Python for aakash

Question #235908

Assume a text file “Test.txt” is already created. Using this file, write a function to create three

files “LOWER.TXT” which contains all the lowercase vowels and “UPPER.TXT” which contains all 

the uppercase vowels and “DIGIT.TXT” which contains all digits



1
Expert's answer
2021-09-11T07:11:48-0400
import ​re


def vowels_digits(filename):
   ​with open(filename) as file:
       ​txt = file.read()
   ​with open('DIGIT.TXT', 'w') as file:
       ​file.write(re.sub(r'\D+', '', txt))
   ​with open('LOWER.TXT', 'w') as file:
       ​file.write(re.sub(r'[^aeiouy]+', '', txt))
   ​with open('UPPER.TXT', 'w') as file:
       ​file.write(re.sub(r'[^AEIOUY]+', '', txt))


vowels_digits('Test.txt')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS