# How do I judge whether the key exists in the typed dict passed to the jit function

**URL:** https://numba.discourse.group/t/how-do-i-judge-whether-the-key-exists-in-the-typed-dict-passed-to-the-jit-function/1833
**Category:** Support: How do I do ...?
**Created:** [March 14, 2023, 4:13pm UTC](https://numba.discourse.group/t/how-do-i-judge-whether-the-key-exists-in-the-typed-dict-passed-to-the-jit-function/1833 "2023-03-14T16:13:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ayem](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Ayem](https://numba.discourse.group/u/Ayem)
#### Post date: [March 14, 2023, 4:13pm UTC](https://numba.discourse.group/t/how-do-i-judge-whether-the-key-exists-in-the-typed-dict-passed-to-the-jit-function/1833/1 "2023-03-14T16:13:42Z")

</div>

Hi, I’m new to numba.  
It seems that **if in dict. keys ()** cannot be used to determine whether there is a key in the dictionary. For example, the following code will report an error.

from numba import njit  
from numba.core import types  
from numba.typed import Dict, List

d = Dict.empty(key\_type=types.unicode\_type, value\_type=types.ListType(types.int64))

d[‘posx’] = List([1, 5, 2])  
d[‘posy’] = List([5, 3, 2])

@njit  
def printdict(d):  
if ‘posx’ in d.keys():  
print('posx: ', d[‘posx’])  
print('posy: ', d[‘posy’])

printdict(d)

---

<div class="post-metadata">

### Author: ![sschaer](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sschaer](https://numba.discourse.group/u/sschaer)
#### Post date: [March 14, 2023, 9:20pm UTC](https://numba.discourse.group/t/how-do-i-judge-whether-the-key-exists-in-the-typed-dict-passed-to-the-jit-function/1833/2 "2023-03-14T21:20:06Z")

</div>

Dear @Ayem

Just do what you would also do in Python:

```auto
from numba import njit
from numba.core import types
from numba.typed import Dict, List

d = Dict.empty(key_type=types.unicode_type, value_type=types.ListType(types.int64))

d['posx'] = List([1, 5, 2])
d['posy'] = List([5, 3, 2])

@njit
def printdict(d):
    if 'posx' in d:
        print('posx: ', d['posx'])
        print('posy: ', d['posy'])

printdict(d)

```

---

<div class="post-metadata">

### Author: ![Ayem](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@Ayem](https://numba.discourse.group/u/Ayem)
#### Post date: [March 15, 2023, 7:56am UTC](https://numba.discourse.group/t/how-do-i-judge-whether-the-key-exists-in-the-typed-dict-passed-to-the-jit-function/1833/4 "2023-03-15T07:56:50Z")

</div>

Thanks 😘,I’m too silly 🥲.
