Editor

Sort Lines Into Two Files

#585 · File handling · Intermediate · 60 XP · about 10 min

Write split_by_vowel(source, vowel_file, other_file) that reads the text file source line by line:

  • A line that starts with a vowel (a, e, i, o or u, in upper or lower case) is copied into vowel_file.
  • Every other line is copied into other_file.
  • A line that is empty or holds only spaces goes into neither file.

Copy each line's text as it is and end every copied line with a newline. Replace whatever the two files held before. Return a tuple (vowel_lines, other_lines) with how many lines went into each file.

Example

If food.txt holds:

apple pie
Banana split

Orange juice
cherry

then split_by_vowel('food.txt', 'vowels.txt', 'others.txt') returns (2, 2). vowels.txt holds apple pie and Orange juice, and others.txt holds Banana split and cherry.

Note

A line that is not blank never starts with a space.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.