0
    Dictionary={
         "b":"कू", 
         "c":"कु",
         "x":"श",

         "A":"क"


def marathi(message):
    dec=''
    for letter in message:  
        for key, value in MARATHI.items():
             if letter == value:
               dec+=key
    print(dec) 



    returning_key_for_value_String='शकुकू'

    marathi(returning_key_for_value_String)
    #output=xAA

While running the function to get back the key from the values of a dictionary,the function is providing the key of "कू" as "A" , but it should be returning "b".It looks like the function is taking only "क", due to which the expected output is not coming.

Jan Wilamowski
  • 3,308
  • 2
  • 10
  • 23
  • Because you have composed characters in your string: `list('शकुकू')` gives `['श', 'क', 'ु', 'क', 'ू']` – Jan Wilamowski Jul 20 '21 at 07:53
  • Does this answer your question? [How do I compare characters with combining diacritic marks ɔ̃, ɛ̃ and ɑ̃ to unaccented ones in python (imported from a utf-8 encoded text file)?](https://stackoverflow.com/questions/67335977/how-do-i-compare-characters-with-combining-diacritic-marks-%c9%94%cc%83-%c9%9b%cc%83-and-%c9%91%cc%83-to-unac) – Jan Wilamowski Jul 20 '21 at 08:35
  • @JanWilamowski How can iterate over it ,if i want them to be considered as one ,rather than two things – Rutvikk Walde Jul 20 '21 at 10:08

1 Answers1

0

You'll want to divide your string into grapheme clusters because it actually contains both letters and nonspacing combining marks:

>>> list('शकुकू')
['श', 'क', 'ु', 'क', 'ू']

The regex module can extract them via the \X pattern:

>>> import regex
>>> regex.findall(r'\X', 'शकुकू')
['श', 'कु', 'कू']

Source

Then, you can compare each of these individual characters to your reference dictionary.

Jan Wilamowski
  • 3,308
  • 2
  • 10
  • 23