Question

Write a Python function uniqueLast(S) that returns True if and only if the last element of...

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

Homework Answers

Answer #1
# 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]))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a python function isogram(S) that returns True if and only if no character appears more...
Write a python function isogram(S) that returns True if and only if no character appears more than once in the input string S.
Python Question Write the body of a function all_same_type(L) that consumes a list of any type...
Python Question Write the body of a function all_same_type(L) that consumes a list of any type and returns true if and only if each element in the list has the same type. Examples: all_same_type([]) => True all_same_type([2, 5, 3]) => True all_same_type([2, 'R', 4.56]) => False
Write a python function called unique words that takes a phrase as an input string and...
Write a python function called unique words that takes a phrase as an input string and returns a list of the unique words found in that phrase. The words should be listed in alphabetical order.
Write a LISP function REMOVELAST which removes the last element of a given list. For example:...
Write a LISP function REMOVELAST which removes the last element of a given list. For example: (REMOVELAST ‘(A (A B) C)) Returns the list (A (A B)) and (REMOVELAST ‘(A B (C D))) Returns the list (A B)
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a function that returns the largest element of an array? Your function should accept a...
Write a function that returns the largest element of an array? Your function should accept a 1-D array as an input and return the largest number. You may assume all numbers are integers. CODE IN C++ PLEASE
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
In Python: Problem 5] Write a function that accepts a list as argument and returns a...
In Python: Problem 5] Write a function that accepts a list as argument and returns a list that contains: (1) The positive elements of the taken list (2) The negative elements of the taken list (3) The odd elements of the taken list (4) The even elements of the taken list