0

I need to unshuffle function in Python. My code is:

def deshuffle_order(sftxt,order):
    sftxt_out=[None]*len(sftxt)
    for i, j in enumerate(order):
        sftxt_out[j]=sftxt[i]
    return sftxt_out

print(deshuffle_order('cbda',[2,1,3,0]))

I want the results of abcd but when I run my code the output is ['a', 'b', 'c', 'd']

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

2

For doing this you will have to do a small change in your code

def deshuffle_order(sftxt,order):
    sftxt_out=[None]*len(sftxt)
    for i, j in enumerate(order):
        sftxt_out[j]=sftxt[i]
    return ''.join(sftxt_out)

print(deshuffle_order('cbda',[2,1,3,0]))

as join will return a string

Jack
  • 222
  • 2
  • 12