A
A
anokhovd2018-07-29 15:42:25
Python
anokhovd, 2018-07-29 15:42:25

How to check if an element is in a list that is in a dictionary?

I need to check if the element I need is in the list which is in the dictionary, how can I do this?
dict = {ids:[1,2,3]}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2018-07-29
@anokhovd

In [1]: dict = {'ids': [1,2,3]}

In [2]: 1 in dict['ids']
Out[2]: True

In [3]: 123 in dict['ids']
Out[3]: False

In [4]: 1 in dict.get('ids')
Out[4]: True

In [5]: 1 in dict.get('ids1', [])
Out[5]: False

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question