question 184 Files & Directories · easy
Check a fixed-width payment file
A bank accepts payment files in which every record is exactly the same width: a 10-character payment ID, a space, and a 10-character zero-padded amount. Before uploading, find the lines that would be rejected.
Function
bad_lines(path, width)Returnsthe line numbers (the first line is 1) whose length, not counting the newline, is not
width, in orderRulesspaces are part of a record and count towards its length; a blank line is a bad record; an empty file gives
[]payments.txtfive lines; line 3 has an unpadded amount and line 4 is blank
Examples
callbad_lines('payments.txt', 21)returns[3, 4]
callbad_lines('payments.txt', 17)returns[1, 2, 4, 5]
callbad_lines('empty.txt', 21)returns[]