From 1fa164c40e2fd38f5d53a1e8f91c11fd7695de10 Mon Sep 17 00:00:00 2001 From: Danh Nguyen Date: Sat, 3 Feb 2018 11:15:07 -0800 Subject: [PATCH] Resolve Issue #40: Python 2 print statements changed to use Python 3 print function (#50) * Update 01_selection_sort.py Updated last print statement for Python 3 print function. * Update 01_countdown.py Updated print statement to print function for Python 3. * Update 05_quicksort.py Updated print statement to print function for Python 3. * Update 01_price_of_groceries.py Condensed dictionary creation into one line, edited print statement to a print function for Python 3. * Update 01_set_covering.py Changed print statement to print function for Python 3. * Update 01_binary_search.py Changed print statements to print function for Python 3. --- 01_introduction_to_algorithms/python/01_binary_search.py | 4 ++-- 02_selection_sort/python/01_selection_sort.py | 2 +- 03_recursion/python/01_countdown.py | 2 +- 04_quicksort/python/05_quicksort.py | 2 +- 05_hash_tables/python/01_price_of_groceries.py | 9 ++------- 08_greedy_algorithms/python/01_set_covering.py | 2 +- 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/01_introduction_to_algorithms/python/01_binary_search.py b/01_introduction_to_algorithms/python/01_binary_search.py index d053232..35ed5cb 100644 --- a/01_introduction_to_algorithms/python/01_binary_search.py +++ b/01_introduction_to_algorithms/python/01_binary_search.py @@ -22,7 +22,7 @@ def binary_search(list, item): return None my_list = [1, 3, 5, 7, 9] -print binary_search(my_list, 3) # => 1 +print(binary_search(my_list, 3)) # => 1 # 'None' means nil in Python. We use to indicate that the item wasn't found. -print binary_search(my_list, -1) # => None +print(binary_search(my_list, -1)) # => None diff --git a/02_selection_sort/python/01_selection_sort.py b/02_selection_sort/python/01_selection_sort.py index 4173eb5..e6fefa9 100644 --- a/02_selection_sort/python/01_selection_sort.py +++ b/02_selection_sort/python/01_selection_sort.py @@ -19,4 +19,4 @@ def selectionSort(arr): newArr.append(arr.pop(smallest)) return newArr -print selectionSort([5, 3, 6, 2, 10]) +print(selectionSort([5, 3, 6, 2, 10])) diff --git a/03_recursion/python/01_countdown.py b/03_recursion/python/01_countdown.py index 69c652c..9793384 100644 --- a/03_recursion/python/01_countdown.py +++ b/03_recursion/python/01_countdown.py @@ -1,5 +1,5 @@ def countdown(i): - print i + print(i) # base case if i <= 0: return diff --git a/04_quicksort/python/05_quicksort.py b/04_quicksort/python/05_quicksort.py index bb98746..dfd2af5 100644 --- a/04_quicksort/python/05_quicksort.py +++ b/04_quicksort/python/05_quicksort.py @@ -11,4 +11,4 @@ def quicksort(array): greater = [i for i in array[1:] if i > pivot] return quicksort(less) + [pivot] + quicksort(greater) -print quicksort([10, 5, 2, 3]) +print(quicksort([10, 5, 2, 3])) diff --git a/05_hash_tables/python/01_price_of_groceries.py b/05_hash_tables/python/01_price_of_groceries.py index 6eeddb4..07998bb 100644 --- a/05_hash_tables/python/01_price_of_groceries.py +++ b/05_hash_tables/python/01_price_of_groceries.py @@ -1,7 +1,2 @@ -book = dict() -# an apple costs 67 cents -book["apple"] = 0.67 -# milk costs $1.49 -book["milk"] = 1.49 -book["avocado"] = 1.49 -print book +book = {"apple": 0.67, "milk": 1.49, "avocado": 1.49} +print(book) diff --git a/08_greedy_algorithms/python/01_set_covering.py b/08_greedy_algorithms/python/01_set_covering.py index e447857..bbd1b5f 100644 --- a/08_greedy_algorithms/python/01_set_covering.py +++ b/08_greedy_algorithms/python/01_set_covering.py @@ -22,4 +22,4 @@ while states_needed: states_needed -= states_covered final_stations.add(best_station) -print final_stations +print(final_stations)