Skip to content

Instantly share code, notes, and snippets.

@jayrhynas
Created October 16, 2021 21:21
Show Gist options
  • Save jayrhynas/05ceaf0b316ef1bb4c29d340bce527a8 to your computer and use it in GitHub Desktop.
Save jayrhynas/05ceaf0b316ef1bb4c29d340bce527a8 to your computer and use it in GitHub Desktop.
import re
def findNeedles(haystack, needles):
if len(needles) > 5:
print "Too many needles"
else:
countArray = [0] * len(needles)
for index, needle in enumerate(needles):
words = re.split(r'[ \'\"\t\n\b\f\r]', haystack)
for word in words:
if word == needle:
countArray[index] = countArray[index] + 1
for index, needle in enumerate(needles):
print "{}: {}".format(needle, countArray[index])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment