简体   繁体   English

用Python识别Unicode字符串中表情符号的最快方法

[英]Fastest Way to recognise emoji in the unicode string with Python

Hy volk, 你好

is there any fastest ways to recognize if given char is emoji? 有没有最快的方法来识别给定的字符是否为表情符号?

Till this moment i found the following solution: 直到这一刻,我找到了以下解决方案:

import emoji
character in emoji.UNICODE_EMOJI

But it seems to be a not the best one, because to check if given char is in the dict, because you need to compute hash function and make lookup. 但这似乎不是最好的方法,因为要检查给定的char是否在dict中,因为您需要计算哈希函数并进行查找。 What I mention, maybe it it possible just to check, if emoji Code point is inside of some range of Unicode code points, which are emojis. 我所说的,也许可以检查一下emoji表情符号是否在Unicode编码表情符号的范围内。 Any ideas, how to implement it? 有什么想法,如何执行呢?

Thx u in advance! 提前谢谢你!

If what you are looking for is faster lookups in a list and you don't have any duplicates, you can try replacing list() with a set() instead. 如果您要查找的是列表中的快速查找,并且没有重复项,则可以尝试使用set()代替list()

Similar problem: https://stackoverflow.com/a/5993659/7570485 相似的问题: https : //stackoverflow.com/a/5993659/7570485

Update: 更新:

As far as I know, you can't get any faster lookups than a dict() . 据我所知,您无法获得比dict()更快的查找。 Average time complexity for dict lookup is O(1) . 字典查找的平均时间复杂度为O(1) You could try intern() in sys module to gain a small performance boost. 您可以在sys模块中尝试intern()来获得较小的性能提升。

Source: https://stackoverflow.com/a/40694623/7570485 资料来源: https : //stackoverflow.com/a/40694623/7570485

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM