Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to deal with emoji's like πŸ‘¨πŸ½β€πŸ‘©πŸ½β€πŸ‘§πŸ½ #256

Closed
lsmith77 opened this issue May 11, 2023 · 1 comment Β· Fixed by #259
Closed

Comments

@lsmith77
Copy link

Python's unicode support with str in principle means that any multibyte character is a single character. but it appears that such an emoji breaks this rule, which is complicating dealing with such emoji's.

in my case I want to detect such an emoji and propose alternatives with other gender/skin tone compositions

k = 0
for i in [*"πŸ‘¨πŸ½β€πŸ‘©πŸ½β€πŸ‘§πŸ½"]:
    print(str(k) + ": " + i)
    k += 1

results in

0: πŸ‘¨
1: 🏽
2: ‍
3: πŸ‘©
4: 🏽
5: ‍
6: πŸ‘§
7: 🏽
@cvzi
Copy link
Contributor

cvzi commented May 11, 2023

These kind of emoji are displayed together because of \u200d in Unicode, called Zero-width-joiner. At position 2 and 5 there is an invisible \u200d.

If you want to find emoji in a string as a single element, the regex library might be helpful with the \X-"grapheme" pattern:

k = 0
for i in regex.findall("\X", "testπŸ‘¨πŸ½β€πŸ‘©πŸ½β€πŸ‘§πŸ½string"):
    print(str(k) + ": " + i)
    k += 1
0: t
1: e
2: s
3: t
4: πŸ‘¨πŸ½β€πŸ‘©πŸ½β€πŸ‘§πŸ½
5: s
6: t
7: r
8: i
9: n
10: g

Finding them with this library is limited, the default skin color works, but others are not supported yet, see #204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants