pythonstringdictionaryoperations

python dictionary string operations


Currently I have my data in a directory

myDict = {'a':'Andy','b':'Bill','c':'Carly' }

I want to achieve something like

input = a --> output = Andy

input = ab --> output = Andy Bill

input = abc --> output = Andy Bill Carly

How can I do that ? Please help me


Solution

  • def girdi_al():
        isim = input("isim giriniz: ")
        return isim
    
    def isim_donustur(isim):
        cikti = isim()
    
        donusum = {'a':'Ankara','b':'Bursa','c':'Ceyhan'}
    
        string = ''
    
        for char in cikti:
            string += donusum[char] + ' '
    
        print(string )
    
    def main():
        isim_donustur(girdi_al)
    
    # === main ===
    main()