Skip to content

Instantly share code, notes, and snippets.

@darius
Created July 23, 2013 23:21
Show Gist options
  • Select an option

  • Save darius/6066998 to your computer and use it in GitHub Desktop.

Select an option

Save darius/6066998 to your computer and use it in GitHub Desktop.
# My solution to a problem in https://github.com/darius/regexercise
def search(strings, chars):
"""Given a sequence of strings and an iterator of chars, return True
if any of the strings would be a substring of ''.join(chars); but
only consume chars up to the end of the match."""
if not all(strings):
return True
tails = []
for ch in chars:
tails = [tail[1:] for tail in strings + tails if tail[0] == ch]
if not all(tails):
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment