Answer to Question #297477 in Python for Ram

Question #297477

String Concatenation


Disha has three strings A, B, and C consisting of lowercase letters.She also has a string T consisting only of characters 1, 2 and 3.

She wants to concatenate the three strings according to the characters in T.

Your task is to print the final output string.


Note: Formally, follow the below instructions:

* For each integer i such that 1<=i<=|T|, let the string si be defined as follows:

  • A if Ti = 1.
  • B if Ti = 2.
  • C if Ti = 3.

*Concatenate the strings s1,s2,...,s|T| in this order and print the resulting string.


Sample Input1

mari

to

zzo

1321


Sample Output1

marizzotomari


1
Expert's answer
2022-02-16T04:45:22-0500
def str_concat(A, B, C, T):
    res = ''
    for Ti in T:
        if Ti == '1':
            res += A
        elif Ti == '2':
            res += B
        elif Ti == '3':
            res += C
    return res


def main():
    A = input()
    B = input()
    C = input()
    T = input()

    res = str_concat(A, B, C, T)
    print(res)


main()

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