My task is to write only one line of code in Python. The code should do the following: I need to print out filenames of txt.files, which include at least one line of words, starting with only vowels (each word needs to start with a vowel from at least one line). My code is:
[filename for filename in listdir(".")if filename.endswith('.txt') and [line for line in open(filename) if ([word for word in line.split() if word[0] in ['a','e','i','o','u']])]]
I tried to use os.listdir(), but I am not allowed to write more than one sentence. My code also prints all 3 of my txt.files, even if one text file doesn´t include a sentence with words, which all start with vowels.
You could try the following one-liner:
OUTPUT:
Test files
Tested with
file1.txt,file2.txtandfile3.txt.file1.txt:
file2.txt:
file3.txt:
Note
You can also use: