Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I see people are using any to gather another list to see if an item exists in a list, but is there a quick way to just do?:

if list.contains(myItem): 

# do something

1 Answer

0 votes
by (106k points)

Yes, there is a sort contains a function for lists you can use this syntax:

if myItem in list: 

# do something

Also, inverse operator:

if myItem not in list: 

# do something

It's work fine for lists, tuples, sets and dicts check keys.

To know more about this you can have a look at the following video tutorial:-

Browse Categories

...