I have a function that have to return True if and only if all the ints in L1 are the lengths of the strings in L2 at the corresponding positions. and the Precondition: len(L1) == len(L2).
EXAMPLE:
>>> are_lengths_of_strs([4, 0, 2], ['abcd', '', 'ef'])
True
Below is the function:
def are_lengths_of_strs(L1, L2):
result = True
for i in range(len(L1)):
if i in len(L1) != len(L2):
result = False
return result
It result in a error. The line if i in len(L1) != len(L2): is the wrong . Can someone help me in this line ??
Obs : I have to use !=
Corrected version of your code:
Note that this is not pythonic, because you don’t in fact need an index here:
Even shorter: