how to make decode unction that can rearrange and sorting input based on integer input?

Viewed 41

I wanna make a function named decode. It can rearrange the sort's list of input_string1 based on input_srting2.

Example:

input_string1 = "a,b,c"
input_string2 = "2,0,1"

ouput = : "c,a,b"

\

def decode(input_string1, input_string2):

try:
    input_string_1 = int(input_string_2)
except ValueError:
    value = input_string_2.lower()
return value
1 Answers

If the indices in the second string are separated by sep, then the following implementation works:

def decode(s1: str, s2: str, sep=','):
    return sep.join(s1.split(sep)[int(i)] for i in s2.split(sep))
Related