+ 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
4 odpowiedzi
+ 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.
+ 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)
+ 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.
+ 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😅