Please tell me how to use python to write this code, thanks. Concatenate Items W
ID: 3573169 • Letter: P
Question
Please tell me how to use python to write this code, thanks.
Concatenate Items Write a function that takes in a list and two indices, and returns the concatenation of the items at the indices as long as the indices are not right next to each other. If neighboring indices are entered, give the user an appropriate message. Note: You should not assume that the caller will input the correct data. Determine the appropriate pre-conditions and use assertions to test each. Determine the appropriate equivalence classes and write unit tests representing each.Explanation / Answer
def concat(l,a,b):
if(a-b == 1 or b-a==1):
return "Cannot concatinate neighboring indeces"
else:
return str(l[a])+str(l[b])
l = [1,2,3,4,5]
assert(concat(l,1,3) == '24'), "failed"
assert(concat(l,1,2) == 'Cannot concatinate neighboring indeces'),"failed"