An error with arithmetic arranger project

Tell us what’s happening:

I have written a code for the arithmetic_arranger project. It runs when I have them in parts but when I run it as a whole program it shows me an error:

" File “/home/runner/UnusedWelllitMarketing/arithmetic_arranger.py”, line 23, in arithmetic_arranger
elif not sign in dict:
TypeError: unhashable type: ‘list’"

Your code so far

    import operator

def int_check(num):
if num == int(num):
return True
else:
return False

def arithmetic_arranger(problems, sp=False):
arranged_problems = “”
dict = {"+": operator.add, “-”: operator.sub}
x = 0 #This is the first problem
f1 = [*range(len(problems)) ] #First number of operation is in range of length of first problem
sign = [*range(len(problems))] #sign of operation is in range of length of first problem
f3 = [*range(len(problems)) ] #Second number of operation is in range of length of second problem
for i in problems:
f1 = i.split()
sign = i.split()
f3 = i.split()
if len(problems) > 5:
return “Error: Too many problems”
elif not sign in dict:
print(sign)
return “Error: Operator must be ‘+’ or ‘-’.”
elif not (not int_check(f1) and int_check(f3)):
return “Error: Numbers must only contain digits.”
elif len(f1) > 4 or len(f3) > 4:
return “Error: Numbers cannot be more than four digits.”
x += 1

#Format the problems vertically

for i in range(problems):
    length = max(len(f1[i]), len(f3[i])) + 2
    top = str(f1[i]).rjust(length)
    bottom = sign[i] + str(f3[i]).rjust(length - 1)
    lines = " "
    for s in range(problems):
        lines += "-"
if sp:
    for i in range(len(problems)):
        arranged_problems += top + "\n" + bottom + "\n" + lines

return arranged_problems

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15.

Challenge: Arithmetic Formatter

Link to the challenge:

Error means that it tried to check whether list is a key within dictionary. That’s not possible, as dictionary can’t have as key something that is a mutable type.

Thanks for that! I will find the issue, I believe I am missing a link between my loops.

Thanks again!

elif not sign in dict:
print(sign) >>>>>sign [‘123’, ‘+’, ‘49’]

the ‘sign’ on line 1 above is a list, you need to get the index of the char(+/-) you’re trying to search in dict

have a good day.

Yep got it! I finally finished this project!

Thanks for all the insight! Appreciate it!