0

I am trying to use emojis.get() != set() to determine if an emoji is in a string. When used on individual strings, it always works; however, it only works on certain emojis when looping through the characters of a string or strings in a list. (This isn't my actual code, just a simplified example of what's happening):

for i in 'Game ✔️':
    print(i, type(i), emojis.get(i), emojis.get(i) != set())
print('✔️', type('✔️'), emojis.get('✔️'), emojis.get('✔️') != set())
#Out:
#G <class 'str'> set() False
#a <class 'str'> set() False
#m <class 'str'> set() False
#e <class 'str'> set() False
#  <class 'str'> set() False
#✔ <class 'str'> set() False
#<class 'str'> set() False
#✔️ <class 'str'> {'✔️'} True

for i in 'Game ':
    print(i, type(i), emojis.get(i), emojis.get(i) != set())
print('', type(''), emojis.get(''), emojis.get('') != set())
#Out:
#G <class 'str'> set() False
#a <class 'str'> set() False
#m <class 'str'> set() False
#e <class 'str'> set() False
#  <class 'str'> set() False
# <class 'str'> {''} True
# <class 'str'> {''} True


j = []
for i in 'Game ✔️':
    j.append(i)
for k in j:
    print(k, emojis.get(k))
print(j)
#Out:
#G set()
#a set()
#m set()
#e set()
#  set()
#✔ set()
#️ set()
#['G', 'a', 'm', 'e', ' ', '✔', '️']

j = []
for i in 'Game ':
    j.append(i)
for k in j:
    print(k, emojis.get(k))
print(j)
#Out:
#G set()
#a set()
#m set()
#e set()
#  set()
# {''}
#['G', 'a', 'm', 'e', ' ', '']

I'm not sure what the ️️ is after the checkmark or why it is being added to the list as an empty string.

Edit: I am now using len(emoji.demojize()) > 1 or character == '' instead of emojis.get() != set() after DYZ's comment about the invisible character. I could not figure out how to fix the problem still using the emojis package.

Emily
  • 1
  • 1
  • Does this answer your question? [Some emojis (e.g. ☁) have two unicode, u'\u2601' and u'\u2601\ufe0f'. What does u'\ufe0f' mean? Is it the same if I delete it?](https://stackoverflow.com/questions/38100329/some-emojis-e-g-have-two-unicode-u-u2601-and-u-u2601-ufe0f-what-does) – DYZ Jun 06 '20 at 07:12
  • There is an extra invisible character 0xfe0f in the string with the checkmark. – DYZ Jun 06 '20 at 07:13
  • I don't think the article helped with this problem, but I am new to coding so it might help someone who knows more than I do. I just edited with my solution after I couldn't figure out how to deal with the invisible character while still using the emojis package. – Emily Jun 06 '20 at 15:35

0 Answers0