0
How to check if multiple integers are in a list ?
How to check if 1 or 2 or 3 is in a list [4,5,2,6] and return true if the list contains at least 1 or 2 or 3
6 ответов
+ 3
You can do it by just iterating through the list and check of required condition for every element of the list.
Or
You can make an hash map of the list if you want the check for a lot of values.
+ 2
Use the or keyword multiple times in you condition
Like
if ( 1 in list or 2 in list or 3 in list ):
To understand it in a better way
Here's the code .
https://code.sololearn.com/c5QjZHQVDBnc/?ref=app
I hope it will help you.
Thank you.
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 thank you! Nice and concise! How did you learn you could use a for loop like this that allows you to define a variable from one list and iterate through list b to determine if that var exists ? I've spent a day searching for documentation on the (i in a for i in b) but cannot find anything to learn more.. just keeps bringing me to normal for loops i.e. for x in b:
0
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 check if [21,3,4,88,9,2,1,25] is in
[1,54,87,45,65,34,3,6,9,47,21,23,31,64]
This would return true because 1 from the first list in the second list