(Python) Type Error: 'function' object is not subscriptable

Viewed 31

Hi I have the block of code here

def name_emoji(s):
    return(s in emoji.is_emoji['en'])

assert(name_emoji("❤️"))
assert(not name_emoji(":-)"))

I do not know what I am doing wrong but I keep getting this error:

TypeError                                 Traceback (most recent call last)
Input In [34], in <cell line: 4>()
      1 def name_emoji(s):
      2     return(s in emoji.is_emoji['en'])
----> 4 assert(name_emoji("❤️"))
      5 assert(not name_emoji(":-)"))

Input In [34], in name_emoji(s)
      1 def name_emoji(s):
----> 2     return(s in emoji.is_emoji['en'])

TypeError: 'function' object is not subscriptable
1 Answers

The error "something is not subscriptable" points out that you are trying to access data using the indexing operator [] on some object which is not array like. In your case, emoji.is_emoji is actually a function. Maybe you intended to call the function and use indexing on the result, which looks like

emoji.is_emoji()['en']`

Or maybe you only need to pass the 'en' string as a parameter, which looks like:

emoji.is_emoji('en')
Related