How to return a string by concatenating characters in python

937 views Asked by At

I have written the following code in Python 2.7

class BinaryCode:
    def decode(self, message):
        result = str(0)
        result += str(message[0])
        for i in range(1, len(message)-1):
            result += str(int(message[i])-int(result[i])-int(result[i-1]))
        return result

When I initialise message as 123210122, I want the result to be 011100011 but instead it's {"0", "1", "1", "1", "0", "0", "0", "1", "1"}. How to do this?

This is a topcoder SRM 144 Div 2 problem and this was the result.

enter image description here

Now, when I run this code in IDLE it gives me a string but then why its not working in topcoder?

1

There are 1 answers

0
hspandher On

Just change last line of function to return ''.join(result).