Last active
August 23, 2016 09:34
-
-
Save JustusW/8f4a902f292ac53c0dfcabfa018a24a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 + ['']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't have a python console to check available, but it should run ;)