小编Vin*_*una的帖子

如何正确迭代 Python 中的 unicode 字符

我想遍历一个字符串并输出所有表情符号。

我正在尝试遍历字符,并根据表情符号列表检查它们。

但是,python 似乎将 unicode 字符拆分为较小的字符,从而破坏了我的代码。例子:

>>> list(u'Test \U0001f60d')
[u'T', u'e', u's', u't', u' ', u'\ud83d', u'\ude0d']
Run Code Online (Sandbox Code Playgroud)

有什么想法为什么 u'\U0001f60d' 会分裂?

或者有什么更好的方法来提取所有表情符号?这是我的原始提取代码:

def get_emojis(text):
  emojis = []
  for character in text:
    if character in EMOJI_SET:
      emojis.append(character)
  return emojis
Run Code Online (Sandbox Code Playgroud)

python unicode python-unicode

2
推荐指数
1
解决办法
1974
查看次数

标签 统计

python ×1

python-unicode ×1

unicode ×1