Created
May 22, 2009 20:14
-
-
Save dreverri/116331 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
def is_perm(ss,s): | |
for l in ss: | |
if s.find(l) != -1: | |
s = s.replace(l,"",1) | |
else: | |
return False | |
return True | |
if __name__ == "__main__": | |
lines = [ | |
"line 1", | |
"line 2", | |
"line 3", | |
"line 4", | |
"line 5" | |
] | |
string_to_match = "line 123" | |
print("Find lines that are permutations of \"" + string_to_match + "\"") | |
print("Lines to match:") | |
print(lines) | |
matches = [l for l in lines if is_perm(l,string_to_match)] | |
print("Matching lines:") | |
print(matches) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment