Skip to content

Instantly share code, notes, and snippets.

@JustusW
Last active August 23, 2016 09:34
Show Gist options
  • Save JustusW/8f4a902f292ac53c0dfcabfa018a24a0 to your computer and use it in GitHub Desktop.
Save JustusW/8f4a902f292ac53c0dfcabfa018a24a0 to your computer and use it in GitHub Desktop.
# Depending on what you want here are a few solutions!
# One line is always nice and this might also be one of the fastest:
any([input[i-2] == 1 and input[i-1] == 3 and v == 4 for i, v in enumerate(input) if i > 2])
# Some like it dynamic:
getSubSequenceLambda = lambda input: any([input[i-2] == 1 and input[i-1] == 3 and v == 4 for i, v in enumerate(input) if i > 2])
# It's a classic:
func getSubSequenceFunc(input):
for i, v in enumerate(input):
# Watchdogs, you love them, or hate them.
if i < 2:
continue
if input[i-2] == 1 and input[i-1] == 3 and v == 4:
return True
return False
# So many assumptions. How about strings?
'.1.3.4.' in '.'.join([''] + input + [''])
@JustusW
Copy link
Author

JustusW commented Aug 23, 2016

I didn't have a python console to check available, but it should run ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment