Skip to content

Instantly share code, notes, and snippets.

@shawnchin
Created July 10, 2012 09:41
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 shawnchin/3082329 to your computer and use it in GitHub Desktop.
Save shawnchin/3082329 to your computer and use it in GitHub Desktop.
pseudocode of answer for SO question 11409942
# http://stackoverflow.com/questions/11409942/function-subseq-python-need-thoughts
function is_sub(s1, s2):
let L1 be the length of s1 and L2 the length of s2
1. if L2 > L1, s2 is definitely not a subset of s1, so return False
2. if the first L2 elements in s1 equals to s2, then s2 is a subset. return True.
3. otherwise, make a recusive call to determine if s2 is a subset of s1[1:] and return the result.
p.s. You might find the slice notation useful. See http://stackoverflow.com/a/509295/115845
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment