+ 4

Please help me fix this logical error

I have written a code that concerts any emoji to heart. It works fine. But I have come across some logical error I don't know how to fix. In my code if you input more than one emoji it will behave weirdly. I tried to fix it myself by adding some condition like: If len(emoji) > 1: print("I only convert EMOJIS to heart") But this doesn't work on all emojis because len("â˜ș") #1 BUT len("đŸ‘©â€âš–ïž") #4 Although I have input only one emoji both the times.. I hope you understand my question and help me solve it. Here's my code https://code.sololearn.com/cturv3OLpkMc/?ref=app

19th Mar 2023, 10:08 AM
â—Šâ€ąâ—â—‰âœżđ•€â„•đ”»đ•€âœżâ—‰â—â€ąâ—Š
â—Šâ€ąâ—â—‰âœżđ•€â„•đ”»đ•€âœżâ—‰â—â€ąâ—Š - avatar
4 Respostas
+ 5
Yeah, you are right. As I said before, Emojis are complex. They usually consist of smaller emojis. For instance, đŸ‘šâ€đŸ‘©â€đŸ‘§â€đŸ‘Š is actually, ['👹', '\u200d', 'đŸ‘©', '\u200d', '👧', '\u200d', '👩']. So, there’s no way to figure that out using pure python. The only solution that comes to my mind is having a dictionary of all available emojis and their corresponding smaller elements and compare them when you’re reading the input. Hope that helped.
19th Mar 2023, 11:22 AM
Alex
Alex - avatar
+ 2
emojis are not simple characters. A lot of them are actually compound, some more than 2, as you have discovered. you can also do this for some characters. example, see how the e was modified s = "cafe" + "\u0301" print(s)
21st Mar 2023, 9:52 AM
Bob_Li
Bob_Li - avatar
+ 1
On line 27, change the condition to this: if check and not check.isdigit() and not check.isalpha() and check not in list and not check.isspace() and len([e for e in check])==1: “len([e for e in check])==1” will guarantee that it’s just one emoji no matter what the length of the emoji is.
19th Mar 2023, 10:54 AM
Alex
Alex - avatar
+ 1
Alex, On your first suggestion: It still doesn't work properly... If I input 'đŸ‘šâ€đŸ‘©â€đŸ‘§â€đŸ‘§' It takes: 👹 Which is not what I expected... On second suggestion: If I input: 'đŸ‘šâ€đŸ‘©â€đŸ‘§â€đŸ‘§' It doesn't work at all😅
19th Mar 2023, 11:00 AM
â—Šâ€ąâ—â—‰âœżđ•€â„•đ”»đ•€âœżâ—‰â—â€ąâ—Š
â—Šâ€ąâ—â—‰âœżđ•€â„•đ”»đ•€âœżâ—‰â—â€ąâ—Š - avatar