Write a program to accept a tuple, extract the last string item of the tuple and return the string after removing the first character of the string.
Quite a tricky description:
If the tuple consists of only strings, then the answer is:
def extract(strings_tuple: tuple):
return strings_tuple[-1][1:]
But if the tuple consists of any objects, then the answer is:
def extract(some_tuple: tuple):
for i in range(len(some_tuple) - 1, 0, -1):
if isinstance(some_tuple[i], str):
return some_tuple[i][1:]
Comments
Leave a comment