Q37Single correct3 Marks7 Aug 2022
Two lists are equal if and only if they satisfy both the conditions given below:
(1) They have the same number of elements. Call this the size of the list.
(2) The element in the first list is the same as the element in the second list for . We are using zero-indexing here.
If both lists are empty, then they are assumed to be equal.
`equality` is a function that accepts two lists `P` and `Q` as arguments and returns `True` if the lists are equal and `False` otherwise. Consider the following possible implementations of this function:
**Code-1**
```
def equality(P, Q):
if len(P) != len(Q):
return False
if len(P) == 0:
return True
if P[0] != Q[0]:
return False
return equality(P[1:], Q[1:])
```
**Code-2**
```
def equality(P, Q):
if len(P) != len(Q):
return False
for elem in P:
if elem not in Q:
return False
return True
```
Which of these two implementations is correct?