Last active
August 29, 2015 13:57
-
-
Save nimish-mehta/9426203 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
import itertools | |
def getAllSentences(input_data): | |
""" | |
take cartesian cross product of list and join to form the sentences to get all sentences. | |
Assumption: The order for sentences is that for every element in ith list create all sentences from i-1..0th list | |
i.e. if list = [[1,2],[3,4],[5]] | |
order of sentences = [135,145,235,245] | |
""" | |
return [" ".join(sentence) for sentence in list(itertools.product(*input_data))] | |
#for testing the function | |
input_data = [ ['Birds', 'Animals', 'Humans'], | |
['are'] , | |
['angry' , 'happy']] | |
for sentence in getAllSentences(input_data): | |
print sentence |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment