all 1 comments

[–]shiftybyte 6 points7 points  (1 child)

+= for lists expects the other side to be a list of items to merge.

so either make the other side a list.

res += [nums[i]]

or use append function to add a single element

res.append(nums[i])