python - Selected joining of lines -
i new python , need solve following (by hand or python): dataset, each file consists of undefined-groups of lines of varying number of numbers, followed 1 line of text incl. dates , numbers (sorry if sentence doesn't make sence):
2, 4, 6, 1, 2, 02-sep-2016, blah blah, blah, 83838338 3, 0, 0, 03-aug-2000, blah, 300033
i need highest number above line of text in front of text , rest deleted:
6,02-sep-2016, blah blah, blah, 83838338 3,03-aug-2000, blah, 300033
i know max()
function, how specify general rule files numbers include, , how can selectively turn numbers int()
without including sentence? tried if
statement len(line)<=3
, not working.
you can read input file using for line in my_file: ...
. if lines want use max
on follow format described (a number followed comma , carriage return), can store them in set integers discarding comma , \n
using slice , transtyping result (i.e. using int(line[:-2])
). max
gives largest element of set, can convert string str()
. distinguish between lines , ones feature date, find in date lines (i.e. characters or -).
Comments
Post a Comment