Code:
import random
import math
t = tuple()
def linsearch(key, l):
count = 0
index = 0
t = tuple()
for i in l:
count += 1
if key == i:
t = (index, count)
return t
index += 1
def binsearch(key, l):
count = 0
low = 0
t = tuple()
high = len(l) - 1
while low < high:
count += 1
mid = (low + high) / 2
if l[mid] < key:
low = mid + 1
elif low < len(l) and l[low] == key:
t = (low, count)
else:
high = mid
return t
def mean(l):
s = 0.0
for i in l:
s += i
return s // len(l)
def sdev(l):
s = 0.0
for i in l:
s += i**2
return math.sqrt((s // len(l)) - mean(l)**2)
def median(l):
if len(l) % 2 == 0:
return (l[len(l) // 2] + l[(len(l) // 2) - 1]) // 2.0
else:
return l[len(l) // 2]
listlen = int(raw_input("List length: "))
testlen = int(raw_input("Test length: "))
maxval = int(raw_input("Maximum value: "))
comlinsort = []
combinsort = []
comlinunsort = []
combinunsort = []
comlinreverse = []
combinreverse = []
for i in range(listlen):
list = []
key = random.randint(1, maxval)
for j in range(listlen):
x = random.randint(1, maxval)
list.append(x)
t = linsearch(key, list)
comlinunsort.append(t[1])
list.sort()
t = linsearch(key, list)
comlinsort.append(t[1])
t = binsearch(key, list)
combinsort.append(t[1])
list.sort(reverse=True)
t = linsearch(key, list)
comlinreverse.append(t[1])
t = binsearch(key, list)
combinreverse.append(t[1])
I keep getting this error:
Code:
Traceback (most recent call last):
File "assign7.py", line 72, in <module>
comlinunsort.append(t[1])
TypeError: 'NoneType' object is unsubscriptable
Comment