Can someone please tell me why I'm getting a TypeError: unhashable type: 'list' error on the print statement below? For some reason it doesn't like the list of data I'm inputting to the function.
from random import randint
from functools import lru_cache
data = []
[data.append(randint(1,1000000)) for i in range(1,1000000)]
data = sorted(data)
low = 0
high = len(data) + 1
target = randint(1,100000)
print(low, high, target)
@lru_cache(maxsize = 1000)
def binary_search(data, target, low, high):
if low > high:
return False
else:
mid = (low + high) // 2
if target == data[mid]:
return True
elif target < data[mid]:
return binary_search(data, target, low, mid+1)
else:
return binary_search(data, target, mid+1, high)
print(binary_search(data, target, low, high))