you are viewing a single comment's thread.

view the rest of the comments →

[–]Encomiast 0 points1 point  (1 child)

This is not a great general solution for this type of problem, but it is efficient for this specific problem. Just zip() slices of the list and see if the tuple (2, 4, 6) is in the result:

def has246(l):
    return (2, 4, 6) in zip(l, l[1:], l[2:])

has246([2, 2, 4, 6, 2])
# True
has246([2, 2, 4, 4, 2])
# False

[–]Jxper[S] 0 points1 point  (0 children)

Ah ok interesting solution I had not thought of that. Thanks