Created
October 16, 2021 21:21
-
-
Save jayrhynas/05ceaf0b316ef1bb4c29d340bce527a8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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