A one-line solution that also throws an error if the length is not equal:
>>> sum(map(lambda x,y: bool(xy),a,b)) 2
Now try entering a different length:
>>> sum(map(lambda x,y: bool(xy),[1,2],[1])) TypeError
How it works: bool (x, y) returns True if the elements are different. Then we map this function to 2 lists and get the list [False, True, False, True, False].
If we enter lists of different lengths into the list of functions (), we get a TypeError
Finally, the sum () function of this Boolean list gives 2.
Max li
source share