Last active
December 30, 2015 17:49
-
-
Save cameronp98/7863856 to your computer and use it in GitHub Desktop.
Returns all strings from the supplied iterable in which the supplied characters are present with the same number of occurrences
This file contains 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
def string_match(data, chars): | |
for item in data: | |
stack = list(item) | |
[stack.pop(stack.index(c)) for c in chars if c in stack] | |
if len(stack) == len(item) - len(chars): | |
yield item | |
data = ["happy", "hand", "charming", "this", "horn", "jamming", "choppy"] | |
chars = "pp" | |
print(list(string_match(data, chars))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment