Answer to Question #328853 in Python for Shubham Tiwari

Question #328853

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.


1
Expert's answer
2022-04-16T03:46:17-0400

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:]




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS