diff --git a/02-go-forth/tf-02.py b/02-go-forth/tf-02.py index 235f467..cd0c67e 100755 --- a/02-go-forth/tf-02.py +++ b/02-go-forth/tf-02.py @@ -93,7 +93,6 @@ def sort(): # Not in style, left as exercise stack.extend(sorted(stack.pop().iteritems(), key=operator.itemgetter(1))) -# # The main function # stack.append(sys.argv[1]) diff --git a/04-cookbook/tf-04.py b/04-cookbook/tf-04.py index 2a1e1f3..423f403 100755 --- a/04-cookbook/tf-04.py +++ b/04-cookbook/tf-04.py @@ -15,9 +15,8 @@ def read_file(path_to_file): contents of the file to the global variable data """ global data - f = open(path_to_file) - data = data + list(f.read()) - f.close() + with open(path_to_file) as f: + data = data + list(f.read()) def filter_chars_and_normalize(): """ @@ -41,9 +40,8 @@ def scan(): def remove_stop_words(): global words - f = open('../stop_words.txt') - stop_words = f.read().split(',') - f.close() + with open('../stop_words.txt') as f: + stop_words = f.read().split(',') # add single-letter words stop_words.extend(list(string.ascii_lowercase)) indexes = []