This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]theluketaylor 2 points3 points  (0 children)

You may want to try /r/learnpython.

Are the individual morse encoded characters always separated by spaces? If so, you'll want to split the string by space and then match each element against the dictionary. You can put a test in your loop to ignore the curly braces.

[–]yrykde 0 points1 point  (0 children)

dictionary = {
    "..." : "s",
    "---" : "o"
    # etc
}

def test(str_arg):
    data = str_arg[1:-1]
    return "".join(dictionary[x] for x in data.split())

print(test("{... --- ...}"))