Skip to content

Instantly share code, notes, and snippets.

@vaultah
Last active October 27, 2016 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaultah/c3eb100140b738d45b6211878dfd24fb to your computer and use it in GitHub Desktop.
Save vaultah/c3eb100140b738d45b6211878dfd24fb to your computer and use it in GitHub Desktop.
Code test

The task is

Given an array of ints, return True if the sequence.. 1, 3, 4 .. appears in the array somewhere.

def f(lst):
return any(lst[x:x + 3] == [1, 3, 4] for x in range(len(lst) - 2))
# Another solution
def f(lst):
return (1, 3, 4) in zip(lst, lst[1:], lst[2:])
assert f([6, 1, 3, 4, 2, 5])
assert not f([5, 6, 1, 2, 3, 4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment