Jun-27-2020, 11:12 AM
(This post was last modified: Jun-27-2020, 11:13 AM by Maxwell123.)
Write the function equal(lst1, lst2), which for two given integer lists will give the result True if these lists are equal after compression and False otherwise. By compression in this task, we mean a replacement on the list
adjacent non-negative (negative) numbers by their sum.
Examples:
• equal([], []) == True
• equal([1], []) == False
• equal([], [1]) == False
• equal([1, -2, 3, -1], [1, -2, 3, -1]) == True
I have no idea how to do it, i have written this, but it seems bad...
adjacent non-negative (negative) numbers by their sum.
Examples:
• equal([], []) == True
• equal([1], []) == False
• equal([], [1]) == False
• equal([1, -2, 3, -1], [1, -2, 3, -1]) == True
I have no idea how to do it, i have written this, but it seems bad...
def equal(lst1, lst2): j = 0 for elt1 in lst1: for k in range(j, len(lst2)): if elt1 == lst2[k]: j = k+1 break else: return False return True