I need a function that takes a list and checks if ['x','y','z'] is in/not in that list in the exact same order.
For example:
list = ['_','x','y','z','_']
if ['x','y','z'] """not""" in list: # `not in` is the actual format of function but commented out to make example easier to explain
return True
else:
return False
I want:
- If the list is
[,'_','x','y','z','_'], then return True - If the list is
[,'_','x','y','a','_'], then return False - If the list is
[,'_','x','z','y','_']then return False
etc.
(Note: the not is commented out because the actual function should return True if ['x','y','z'] not in list: but it is easier to explain without the not condition.)
>Solution :
def your_function(list_of_chars):
return "xyz" in "".join(list_of_chars)
your_list = ['_','x','y','z','_']
your_function(your_list) # == True