From 84f3db6a71ae581517595d4deba15a64dfe2bf00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas?= Date: Fri, 10 Jan 2014 23:19:53 -0800 Subject: [PATCH] Support input files that do not finish with CRLF. --- 01-good-old-times/tf-01.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/01-good-old-times/tf-01.py b/01-good-old-times/tf-01.py index 9ca8a40..9bffc33 100755 --- a/01-good-old-times/tf-01.py +++ b/01-good-old-times/tf-01.py @@ -52,6 +52,9 @@ while True: data[1] = [f.readline()] if data[1] == ['']: # end of input file break + + if data[1][0][len(data[1][0])-1] != '\n': # If it does not end with \n + data[1][0] = data[1][0] + '\n' # Add \n data[2] = None data[3] = 0 # Loop over characters in the line @@ -123,6 +126,6 @@ while True: for tf in data[0:25]: # elimination of symbol tf is exercise if len(tf) == 2: - print tf[0], ' - ', tf[1] + print(tf[0], ' - ', tf[1]) # We're done word_freqs.close()