Help needed in Python ! Thanx

1 A csv file is a text file whose lines are composed by sequences of non-negative decimal integers, separated by commas (,

table.txt

1
2,3
4,5,6
7,8,9,10
10,11,12,13,14
15,16,17,18,19,20

1 “’A csv file is a text file whose lines are composed by sequences of non-negative decimal integers, separated by commas (‘,’). 2 Given a row, the sequence of characters from the beginning of the line up until the first comma form the first integer 3 (written in base 10) – as usual, the index of the first integer of a row, is 0. 4 Analogously, the sequence of characters starting from right after the i-th comma and ending right before the (i+1)-th comma 5 (or, if the line ends before the (i+1)-th comma is found, ending at the end of the line), form the integer (written in base 10) having index i in the line. 6 7 Write a function max(fileName, i) that, given a fileName of a csv file, returns the maximum of the integers in the fields of index i of the various lines of the file. 8 If a given line contains less than i+1 integers, then it does not contain the field of index i. If no line contains the field of index i, then the function should return None. 9 10 Example: 11 If the file “table.txt” contains: 12 —- 131,1,1,1 14 2,2,2 15 3,10,5,0,7 16 2 17 18 19 Then, max(“table. txt”, 0) should return 3; max(‘table.txt’, 1) should return 10; 21 max(‘table.txt’, 4) should return 7. 20



Source link

Leave a Reply

Your email address will not be published.