TypeError: object of type 'NoneType' has no len(). Codewars

Код работает, но на CODEWARS Выводит ниже приписка и поэтому не получается cдать кату:

Traceback (most recent call last):
  File "main.py", line 21, in <module>
    test.assert_equals(comp(a1, a2), False)
  File "/home/codewarrior/solution.py", line 4, in comp
    if len(a) != len(b):
TypeError: object of type 'NoneType' has no len()
#Сравнивает два списка, второй должен состоять из квадратов первого, тогда True
def comp(a, b):
    if a and b is None:
        return True
    if len(a) != len(b):
        return False
    index = 0
    n = 0
    while index != len(a):
        for i in range(0, len(a)):
            if a[index]**2 == b[i]:
                n += 1
                continue
            else:
                continue
        if n != len(a):
            index += 1
    if n/2 == len(a):
        return True
    else:
        return False

Ответы (1 шт):

Автор решения: MaxU

Попробуйте так:

def comp(a, b):
    if a is None and b is None:
        return True
    if a is None or b is None or len(a) != len(b):
        return False            
    return sorted(list(map(lambda x: x**2, a))) == sorted(b)

Тесты:

In [24]: comp([], [1,2])
Out[24]: False

In [25]: comp([], [])
Out[25]: True

In [26]: comp([4, 2, 3], [9, 16, 4])
Out[26]: True
→ Ссылка