A
A
Alexander2020-04-26 01:03:10
Python
Alexander, 2020-04-26 01:03:10

How to find if there are consecutive elements in a list?

Hello, there is such an array

a = ['p', 'p', 'p', 'p', 'p', 'p', 'figure', 'h2', 'figure', 'p', 'p', 'p', 'p', 'p', 'p']

What is the optimal request in python to find out if there is ['p', 'figure', 'h2', 'figure'] in array 'a'?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Shatalov, 2020-04-26
@AlexMine

a = ['p', 'p', 'p', 'p', 'p', 'p', 'figure', 'h2', 'figure', 'p', 'p', 'p', 'p', 'p', 'p']
''.join(['p', 'figure', 'h2', 'figure']) in ''.join(a)
True

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question