Created
July 21, 2017 23:32
-
-
Save cmattoon/7b6e5e0529f44090d23edcc5bb53202d 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
#!/usr/bin/env python | |
import os | |
import sys | |
from itertools import product | |
from random import sample | |
def load(filename): | |
with open(filename) as fd: | |
return filter(lambda x:x, map(lambda x:x.strip(), fd.readlines())) | |
def option1(A, B, n): | |
"""Returns n random items from the product of A+B""" | |
return sample(map(lambda i:i, product(A, B)), n) | |
def as_strings(A, B, n): | |
return map(lambda i:" ".join(i), option1(A, B, n)) | |
def match_phrases(A, B): | |
if len(A) != len(B): | |
print("Lists aren't the same length!") | |
items = [] | |
for i in range(min(len(A), len(B))): | |
#yield A[i] + " " + B[i] | |
items.append("{0} {1}".format(A[i], B[i])) | |
return items | |
if __name__ == '__main__': | |
list1 = load(sys.argv[1]) | |
list2 = load(sys.argv[2]) | |
items = as_strings(list1, list2, 4) | |
print(items) | |
print(match_phrases(list1, list2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment