Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active May 29, 2023 12:37
Show Gist options
  • Select an option

  • Save benigumocom/fe1194f3bb199f73272c293a4e3034ac to your computer and use it in GitHub Desktop.

Select an option

Save benigumocom/fe1194f3bb199f73272c293a4e3034ac to your computer and use it in GitHub Desktop.
【Python】絵文字を含む Unicode 文字列の文字数をカウントする方法と文字ごとの構成要素 👉 https://android.benigumo.com/20230529/python-unicode-emoji/
def dump(data):
print(data)
# https://libraries.io/pypi/regex
ss = regex.findall(r'\X', data)
print(ss)
print(len(ss))
print()
for s in ss:
print(s)
cs = list(s)
for c in cs:
cp = ord(c)
print(' ', r'\U{:08X}'.format(cp), r'0x{:X}'.format(cp), f'({c})')
aAあ😀😍🥸🐻‍❄️😵‍💫🧑🏻‍❤️‍🧑🏼🫡🫶🪿🫛🍋‍🟩🙂‍↕️
['a', 'A', 'あ', '😀', '😍', '🥸', '🐻\u200d❄️', '😵\u200d💫', '🧑🏻\u200d❤️\u200d🧑🏼', '🫡', '🫶', '\U0001fabf', '\U0001fadb', '🍋\u200d🟩', '🙂\u200d↕️']
15
a
\U00000061 0x61 (a)
A
\U00000041 0x41 (A)
\U00003042 0x3042 (あ)
😀
\U0001F600 0x1F600 (😀)
😍
\U0001F60D 0x1F60D (😍)
🥸
\U0001F978 0x1F978 (🥸)
🐻‍❄️
\U0001F43B 0x1F43B (🐻)
\U0000200D 0x200D (‍)
\U00002744 0x2744 (❄)
\U0000FE0F 0xFE0F (️)
😵‍💫
\U0001F635 0x1F635 (😵)
\U0000200D 0x200D (‍)
\U0001F4AB 0x1F4AB (💫)
🧑🏻‍❤️‍🧑🏼
\U0001F9D1 0x1F9D1 (🧑)
\U0001F3FB 0x1F3FB (🏻)
\U0000200D 0x200D (‍)
\U00002764 0x2764 (❤)
\U0000FE0F 0xFE0F (️)
\U0000200D 0x200D (‍)
\U0001F9D1 0x1F9D1 (🧑)
\U0001F3FC 0x1F3FC (🏼)
🫡
\U0001FAE1 0x1FAE1 (🫡)
🫶
\U0001FAF6 0x1FAF6 (🫶)
🪿
\U0001FABF 0x1FABF (🪿)
🫛
\U0001FADB 0x1FADB (🫛)
🍋‍🟩
\U0001F34B 0x1F34B (🍋)
\U0000200D 0x200D (‍)
\U0001F7E9 0x1F7E9 (🟩)
🙂‍↕️
\U0001F642 0x1F642 (🙂)
\U0000200D 0x200D (‍)
\U00002195 0x2195 (↕)
\U0000FE0F 0xFE0F (️)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment