From 33825db6b9bf2af99be5f43c489e679048b56eda Mon Sep 17 00:00:00 2001 From: peterhuang1kimo Date: Mon, 19 Oct 2020 16:51:24 +0800 Subject: [PATCH 1/4] upgrade to python 3 fix TypeError: 'range' object does not support item assignment issue --- python/072_Edit_Distance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/072_Edit_Distance.py b/python/072_Edit_Distance.py index e9033cc..b074085 100644 --- a/python/072_Edit_Distance.py +++ b/python/072_Edit_Distance.py @@ -24,7 +24,7 @@ class Solution(object): def minDistance(self, word1, word2): ls_1, ls_2 = len(word1), len(word2) - dp = range(ls_1 + 1) + dp = list(range(ls_1 + 1)) for j in range(1, ls_2 + 1): pre = dp[0] dp[0] = j From 65841c8df05254cabb1ae019ae877fb2fc4d5607 Mon Sep 17 00:00:00 2001 From: peterhuang1kimo Date: Mon, 19 Oct 2020 16:54:17 +0800 Subject: [PATCH 2/4] upgrade to python 3 Add sample --- python/072_Edit_Distance.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/072_Edit_Distance.py b/python/072_Edit_Distance.py index b074085..f1dd491 100644 --- a/python/072_Edit_Distance.py +++ b/python/072_Edit_Distance.py @@ -36,3 +36,10 @@ def minDistance(self, word1, word2): dp[i] = min(pre + 1, dp[i] + 1, dp[i - 1] + 1) pre = temp return dp[ls_1] + + + if __name__ == '__main__': + # begin + s = Solution() + print (s.minDistance("horse","ros")) + print (s.minDistance("intention","execution")) From 97ca6fb2d395705f69a66348b3902c68da12c18c Mon Sep 17 00:00:00 2001 From: peterhuang1kimo Date: Tue, 20 Oct 2020 09:27:30 +0800 Subject: [PATCH 3/4] upgrade to python 3 fix IndentationError: expected an indented block error --- python/072_Edit_Distance.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/072_Edit_Distance.py b/python/072_Edit_Distance.py index f1dd491..f0cdc13 100644 --- a/python/072_Edit_Distance.py +++ b/python/072_Edit_Distance.py @@ -37,9 +37,9 @@ def minDistance(self, word1, word2): pre = temp return dp[ls_1] - - if __name__ == '__main__': + +if __name__ == '__main__': # begin s = Solution() print (s.minDistance("horse","ros")) - print (s.minDistance("intention","execution")) + print (s.minDistance("intention","execution")) From 97f840cf8dfb1cf32ed860ea8976c3d4e41f4f6c Mon Sep 17 00:00:00 2001 From: peterhuang1kimo Date: Tue, 20 Oct 2020 11:01:57 +0800 Subject: [PATCH 4/4] upgrade to python 3 fix SyntaxError: invalid syntax issue --- python/078_Subsets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/078_Subsets.py b/python/078_Subsets.py index 9e3dfc0..8738707 100644 --- a/python/078_Subsets.py +++ b/python/078_Subsets.py @@ -55,4 +55,4 @@ def subsets(self, nums): if __name__ == "__main__": s = Solution() - print s.subsets([1,2,3]) + print (s.subsets([1,2,3]))