Skip to content

Instantly share code, notes, and snippets.

@dreverri
Created May 22, 2009 20:14
Show Gist options
  • Save dreverri/116331 to your computer and use it in GitHub Desktop.
Save dreverri/116331 to your computer and use it in GitHub Desktop.
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