Write a Python function uniqueLast(S) that returns True if and only if the last element of sequence S is unique in S. Specify any special cases
# function definition # Special case: When list is empty, returning False. since there is no last item. def uniqueLast(S): if len(S) == 0: return False for i in range(len(S) - 1): if S[i] == S[-1]: return False return True # Testing the function here print(uniqueLast([])) print(uniqueLast([1, 2, 3])) print(uniqueLast([3])) print(uniqueLast([4, 7, 9, 7])) print(uniqueLast([6, 2, 4, 9, 3]))
Get Answers For Free
Most questions answered within 1 hours.