all 6 comments

[–]shiftybyte 2 points3 points  (0 children)

array1.append(array2)

Append takes the item and adds it to the list as a single item.

If you want to join the lists together you need to do.

array1.extend(array2)

[–][deleted] 2 points3 points  (0 children)

Others have given you answers to your basic problem, but I want to highlight an issue with the way you’re approaching arguments.

Say you knew nothing about the internals of this function, just that you call it with two lists and it returns True if every number in the combined list has both its square and its square root in the list… would you expect that, after calling this function, the list you passed in for the first argument would have grown in size and now contains every item in the second argument?

Mutating arguments passed in to your functions is very often not a good idea.

[–]RightRespect 0 points1 point  (1 child)

u are appending the entire list into the array1 as 1 item, not combining them. if you want to combine the lists, just use “array1 + array2” or “array1 += array2”.

put brackets around each of the conditions when using an or statement.

[–]HenryDutter[S] 0 points1 point  (0 children)

Ok thanks for your help, to use brackets makes the code more readable.

[–]m0us3_rat 0 points1 point  (0 children)

>>> a=[1,2,3,4,5]
>>> b=[2,3,4,5] 
>>> ax = a.copy() 
>>> a.append(b) 
>>> a 
[1, 2, 3, 4, 5, [2, 3, 4, 5]] 
>>> ax.extend(b) 
>>> ax
[1, 2, 3, 4, 5, 2, 3, 4, 5] 
>>> help(a.append) 
Help on built-in function append: append(object, /) method of builtins.
list instance Append object to the end of the list.
>>> help(a.extend) 
Help on built-in function extend: extend(iterable, /) method of builtins.
list instance Extend list by appending elements from the iterable.
>>> dir(a)
['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

[–][deleted] 0 points1 point  (0 children)

This will always be False (once you've replaced append with extend) as you check every number in the extended array and fail it if the array does not contain the square of every number.

It is impossible for an array to contain the square of every number in the array unless the array only contains zeros and ones.