Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 642 Bytes

2325. Decode the Message.md

File metadata and controls

37 lines (27 loc) · 642 Bytes

Solution

class Solution:
    def decodeMessage(self, key: str, message: str) -> str:

        l=[]
        for i in key:
            if i==" ":      #done to avoid having an element: " "
                continue    #the dict requires alphabet->alphabet
            if i not in l:
                l.append(i)

        al="abcdefghijklmnopqrstuvwxyz"

        d=dict(zip(l, list(al)))

        res=""
        for i in message:
            if i==" ":
                res+=" "
            elif i in d:
                res+=d[i]

        return res
        

Method 2

to avoid " " elements in l,

d={}

l=l.split()
l.join("")