Skip to content

Commit dcff43c

Browse files
author
Philip Guo
committed
changed examples to use 4-space tabs
1 parent d83ceda commit dcff43c

File tree

9 files changed

+56
-56
lines changed

9 files changed

+56
-56
lines changed

example-code/aliasing.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ y.append(7)
99
y = "hello"
1010

1111
def foo(lst):
12-
lst.append("hello")
13-
bar(lst)
12+
lst.append("hello")
13+
bar(lst)
1414

1515
def bar(myLst):
16-
print myLst
16+
print myLst
1717

1818
foo(x)
1919
foo(z)

example-code/fib.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ arr = [1, 1]
55
print arr[0]
66

77
while True:
8-
print arr[-1]
9-
tmp = sum(arr)
10-
arr.append(tmp)
11-
del arr[0]
8+
print arr[-1]
9+
tmp = sum(arr)
10+
arr.append(tmp)
11+
del arr[0]

example-code/map.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf
44

55
def map(func, lst):
6-
if lst == []:
7-
return []
8-
else:
9-
return [func(lst[0])] + map(func, lst[1:])
6+
if lst == []:
7+
return []
8+
else:
9+
return [func(lst[0])] + map(func, lst[1:])
1010

1111
def halveElements(lst):
12-
return map(lambda x: x / 2.0, lst)
12+
return map(lambda x: x / 2.0, lst)
1313

1414
input = [2, 4, 6, 8, 10]
1515
output = halveElements(input)

example-code/memo_fib.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
MemoTable = {}
55

66
def MemoizedFib(n):
7-
if n <= 2:
8-
return 1
7+
if n <= 2:
8+
return 1
99

10-
if n in MemoTable:
11-
return MemoTable[n]
10+
if n in MemoTable:
11+
return MemoTable[n]
1212

13-
MemoTable[n] = MemoizedFib(n-1) + MemoizedFib(n-2)
14-
return MemoTable[n]
13+
MemoTable[n] = MemoizedFib(n-1) + MemoizedFib(n-2)
14+
return MemoTable[n]
1515

1616

1717
res = MemoizedFib(10)

example-code/oop_small.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class A:
2-
x = 1
3-
y = 'hello'
2+
x = 1
3+
y = 'hello'
44

55
class B:
6-
z = 'bye'
6+
z = 'bye'
77

88
class C(A,B):
9-
def salutation(self):
10-
return '%d %s %s' % (self.x, self.y, self.z)
9+
def salutation(self):
10+
return '%d %s %s' % (self.x, self.y, self.z)
1111

1212
inst = C()
1313
print inst.salutation()

example-code/sqrt.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.7
33

44
def sqrt(x):
5-
def average(a, b):
6-
return (a + b) / 2.0
5+
def average(a, b):
6+
return (a + b) / 2.0
77

8-
def is_good_enough(guess):
9-
return (abs((guess * guess) - x) < 0.001)
8+
def is_good_enough(guess):
9+
return (abs((guess * guess) - x) < 0.001)
1010

11-
def improve(guess):
12-
return average(guess, x / guess)
11+
def improve(guess):
12+
return average(guess, x / guess)
1313

14-
def sqrt_iter(guess):
15-
if is_good_enough(guess):
16-
return guess
17-
else:
18-
return sqrt_iter(improve(guess))
14+
def sqrt_iter(guess):
15+
if is_good_enough(guess):
16+
return guess
17+
else:
18+
return sqrt_iter(improve(guess))
1919

20-
return sqrt_iter(1.0)
20+
return sqrt_iter(1.0)
2121

2222

2323
ans = sqrt(9)

example-code/sum.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# http://mit.edu/6.01/mercurial/spring10/www/handouts/readings.pdf
44

55
def summation(low, high, f, next):
6-
s = 0
7-
x = low
8-
while x <= high:
9-
s = s + f(x)
10-
x = next(x)
11-
return s
6+
s = 0
7+
x = low
8+
while x <= high:
9+
s = s + f(x)
10+
x = next(x)
11+
return s
1212

1313
def sumsquares(low, high):
14-
return summation(low, high, lambda x: x**2, lambda x: x+1)
14+
return summation(low, high, lambda x: x**2, lambda x: x+1)
1515

1616
print sumsquares(1, 10)

example-code/towers_of_hanoi.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# move a stack of n disks from stack a to stack b,
22
# using tmp as a temporary stack
33
def TowerOfHanoi(n, a, b, tmp):
4-
if n == 1:
5-
b.append(a.pop())
6-
else:
7-
TowerOfHanoi(n-1, a, tmp, b)
8-
b.append(a.pop())
9-
TowerOfHanoi(n-1, tmp, b, a)
10-
4+
if n == 1:
5+
b.append(a.pop())
6+
else:
7+
TowerOfHanoi(n-1, a, tmp, b)
8+
b.append(a.pop())
9+
TowerOfHanoi(n-1, tmp, b, a)
10+
1111
stack1 = [4,3,2,1]
1212
stack2 = []
1313
stack3 = []

example-code/wentworth_try_finally.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
# How many "survived!" messages will be printed???
88

99
def f(n):
10-
try:
11-
x = 10 / n
12-
print "x is", x
13-
f(n-1)
14-
print "survived!"
15-
finally:
16-
print "Bye from f where n =", n
10+
try:
11+
x = 10 / n
12+
print "x is", x
13+
f(n-1)
14+
print "survived!"
15+
finally:
16+
print "Bye from f where n =", n
1717

1818
f(4)

0 commit comments

Comments
 (0)