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

If I've got an array of strings, can I check to see if a string is in the array without doing a for loop? Specifically, I'm looking for a way to do it within an if statement, so something like this:

if [check that item is in array]:

1 Answer

0 votes
by (106k points)

For lists you can do something as follows:-

if item in my_list: 

# whatever

This works for any collection, not just for lists. For dictionaries, it checks whether the given key is present in the dictionary.

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

Related questions

0 votes
1 answer
asked Oct 14, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.6k users

Browse Categories