I'm getting errors saying that there is a syntax error for the "makeShortest" function that I defined.
- What is the problem here?
- Are there any other issues that might make this function not work at runtime?
def solution(A):
idxDict = defaultdict(list)
for i in range(len(A)):
idxDict[A[i]].append(i)
ans = -1
A.sort()
if len(A) <= 1:
return ans
hasAdj = 0
for i in range(len(A) - 1):
if A[i] != A[i + 1]:
hasAdj += 1
if hasAdj == 1:
ans = makeShortest(idxDict[A[i]], idxDict[A[i + 1]])
else:
ans = min(ans, makeShortest(idxDict[A[i]], idxDict[A[i + 1]]))
return ans
def makeShortest (list1, list2):
ans = abs(list1[0] - list2[0])
for k in range(len(list1)):
for l in range(len(list2)):
ans = min(ans, abs(list1[k] - list2[l])
return ans
def makeShortest (list1, list2)with "pylint(syntax-error)