Skip to content

Instantly share code, notes, and snippets.

@johnholbrook
Created April 10, 2020 15:39
Show Gist options
  • Select an option

  • Save johnholbrook/59cb553792bc1fa932e3cb76cd4315be to your computer and use it in GitHub Desktop.

Select an option

Save johnholbrook/59cb553792bc1fa932e3cb76cd4315be to your computer and use it in GitHub Desktop.
#returns true if strings a and b contain the same letter count
# (i.e., a can be rearranged to form b)
def compare(a,b):
return sorted([i for i in a]) == sorted([i for i in b])
def main():
contents = []
# open the file and separate into lines
with open("enable1.txt", "r") as f:
contents = f.readlines()
# strip trailing \n (not sure why it's there after the call to readlines but whatever)
contents = [word[:-1] for word in contents]
target = "streampa"
for word in contents:
if compare(word, target):
print(word)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment