+ 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 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.
+ 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đ