Question

Define a function funD2(...) which receives a list lst that contains single letters, single digits and...

Define a function funD2(...) which receives a list lst that contains single letters, single digits and single special characters (and the list contains at least one element of each type). The function returns a string that contains the last letter and the last special character of the list, where each is repeated as many times as the sum of all digits in the list.

As an example, the following code fragment: lst = ["a","b","c", 1, 2, "$","%"]
print (funD2(lst))
should produce the output:

ccc%%%

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def funD2(lst):
    last_letter = ''
    last_special = ''
    total = 0
    for ch in lst:
        if type(ch) == int:
            total += ch
        elif ch.isalpha():
            last_letter = ch
        else:
            last_special = ch
    return (last_letter * total) + (last_special * total)


# Testing the function here. ignore/remove the code below if not required
lst = ["a", "b", "c", 1, 2, "$", "%"]
print(funD2(lst))

ccc%%% Process finished with exit code o

Add a comment
Know the answer?
Add Answer to:
Define a function funD2(...) which receives a list lst that contains single letters, single digits and...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT