Skip to content

Instantly share code, notes, and snippets.

View alfredleo's full-sized avatar
:octocat:
Working from Ground Zero

Alfred alfredleo

:octocat:
Working from Ground Zero
  • ITMED
  • Tashkent
View GitHub Profile
@alfredleo
alfredleo / KMP.py
Last active August 29, 2015 14:16 — forked from kylebgorman/KMP.py
#!/usr/bin/env python
# Knuth-Morris-Pratt demonstration
# Kyle Gorman <kgorman@ling.upenn.edu>
#
# A naive Python implementation of a function that returns the (first) index of
# a sequence in a supersequence is the following:
def subsequence(needle, haystack):
"""
Naive subsequence indexer; None if not found