defsum_arrays(array1,array2):print(array1)print(array2)ifnot array1:return array2
ifnot array2:return array1
ifnot array1 andnot array2:return[]if array1 == array2 ==[0]:return[]else:
array1_n =[str(i)for i in array1]
array2_n =[str(i)for i in array2]
ans =int("".join(array1_n))+int("".join(array2_n))
string_num =list(str(ans))# ['-','1','2']
new_string_num =[]print(string_num)if string_num[0]=="-":
first_item = string_num[0]+ string_num[1]
new_string_num.append(first_item)for i inrange(2,len(string_num)):
new_string_num.append(string_num[i])else:
new_string_num = string_num
return[int(i)for i in new_string_num]
Suggested answer
defsum_arrays(ar1,ar2):
answ =[]ifnot ar1 andnot ar2:return[]ifnot ar1:return ar2
ifnot ar2:return ar1
if ar1[0]==0and ar2[0]==0:return[]
sa1 ="".join([str(k)for k in ar1])
sa2 ="".join([str(j)for j in ar2])
r =int(sa1)+int(sa2)ifstr(r)[0]=='-':for s instr(r)[1:]:
answ.append(int(s))
answ[0]*=-1return answ
for s instr(r):
answ.append(int(s))return answ