Check slice with 'in' | Sololearn: Learn to code for FREE!


Check slice with 'in'

A slice of a list can be verified with 'in'? In other words; list_a = [1,2,3,4,5,6] [1,2,3] in list_a False But in this way behavior changes, list_a = [[1,2,3],2,3,4,5,6] [1,2,3] in list_a True Is there any way to do first check correctly?

1/24/2017 12:38:55 PM

Reginaldo Junior

3 Answers

New Answer


in the second example you gave you aren't looking for a slice. the whole [1,2,3] is recognized as a unique element. i think you should iterate among all elements of the second list and check them individually against the first one. you can do this with a for loop for each element in the list. if any element is not found the loop is broken and the function returns false.