diff --git a/bst.py b/bst.py index cff4d36..f09abf9 100755 --- a/bst.py +++ b/bst.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#! /usr/bin/env python3 from random import randint from pprint import PrettyPrinter @@ -18,7 +18,7 @@ class Branch: return "(%s) %s (%s)" % (repr(self.left), self.value, repr(self.right)) def split(xs): - l = len(xs) / 2 + l = int(len(xs) / 2) return (xs[0:l], xs[l], xs[l+1:]) def bst(xs): @@ -33,7 +33,6 @@ def makeBST(xs): def findBST(tree, x): if tree is None: return None - print tree.value if tree.value == x: return tree if x < tree.value: @@ -43,6 +42,6 @@ def findBST(tree, x): test = [randint(1,50) for _ in range(20)] -print test -print "finding %s" % test[4] -print findBST(makeBST(test), test[4]) +print(test) +print("finding %s" % test[4]) +print(findBST(makeBST(test), test[4])) diff --git a/intersection.py b/intersection.py index 9b62d39..c36f616 100755 --- a/intersection.py +++ b/intersection.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#! /usr/bin/env python3 # find the intersection of two lists including duplicate values @@ -15,9 +15,9 @@ def intersection(xs, ys): freqs2 = frequencies(ys) intersection = [] - for k, v in freqs1.iteritems(): + for k, v in freqs1.items(): n = min(v, freqs2[k]) - intersection.extend([k for _ in xrange(n)]) + intersection.extend([k for _ in range(n)]) return intersection -print intersection([1,4,2,6,10,4,4], [7,4,9,10,20,4,10]) +print(intersection([1,4,2,6,10,4,4], [7,4,9,10,20,4,10])) diff --git a/palindrome.py b/palindrome.py index 97a5303..9d5f56c 100755 --- a/palindrome.py +++ b/palindrome.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#! /usr/bin/env python3 # check if a word is palindromic without reversing it @@ -16,4 +16,4 @@ def isPalindrome(word): end -= 1 return retval -print isPalindrome("wwaabbaawwz") +print(isPalindrome("wwaabbaawwz")) diff --git a/pascal.py b/pascal.py index 488fadb..6ac65b6 100755 --- a/pascal.py +++ b/pascal.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#! /usr/bin/env python3 # find the rows of pascal's triangle @@ -8,7 +8,7 @@ def choose(n, k): return choose(n, k-1) * (n-k) / k def pascal(n): - return [choose(n, i) for i in xrange(0, n)] + return [choose(n, i) for i in range(0, n)] -for i in xrange(1, 11): - print pascal(i) +for i in range(1, 11): + print(pascal(i)) diff --git a/phone.py b/phone.py index 7fc2667..21c5a5f 100755 --- a/phone.py +++ b/phone.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#! /usr/bin/env python3 # find all possible permutations of a sequence of phone pad digits (other than 1 and 0) @@ -34,4 +34,4 @@ def numToWords(num): return genAll(lettersets)[0] for num in numToWords("353346"): - print num + print(num) diff --git a/regions.py b/regions.py index 54977fa..7915871 100755 --- a/regions.py +++ b/regions.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#! /usr/bin/env python3 # counts the number of regions in a matrix # vertically and horizontally connected @@ -56,4 +56,4 @@ for y, row in enumerate(testregion): count += 1 exploreField(testregion, x, y) -print count +print(count)