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.