From: Chris Withers on 11 Aug 2010 12:04 Steven D'Aprano wrote: > def strip_blank_lines(lines): > for line in lines: > if not line.isspace(): > yield line > > text = ''.join(strip_blank_lines(lines.split('\n'))) The final version I have is: def strip_blank_lines(text): result = [] for line in text.split('\n'): if line and not line.isspace(): result.append(line) return '\n'.join(result) Any improvements would be very welcome! Chris
First
|
Prev
|
Pages: 1 2 Prev: Line-by-line processing when stdin is not a tty Next: urgent requirement at Hyderabad |