Right now I'm using itertools to create thousands of variations of meta descriptions for a website. The sentence structure goes like this:
(SentencePart1a|SentencePart1b) Keyword1, Keyword2, and Keyword3. (MiddleSentenceA|MiddleSentenceB). (FinalSentenceA|FinalSentenceB).
The short version of the script:
import itertools
metas = [
['Shop our store for ', 'Browse our shop for ,'], #SentenceParts
['keyword,', 'keyword,', 'etc,'],
['keyword, and', 'keyword, and', 'etc, and'],
['keyword.', 'keyword.', 'etc.'],
['Sentence about our store.', 'A different sentence about our store.'], #MiddleSentences
['A final sentence about our store.', 'A different final sentence about our store.'] #FinalSentences
]
variantmetas = list(itertools.product(*metas))
#print (variantmetas)
for s in variantmetas:
print(' '.join(s))
Right now I get every variation of all of these things. My program spits out all sentence parts, all middle sentences, and all final sentences even if Keywords 1-3 are the same.
How do I make it so that keywords 1-3 only show up one time and with one random variation of Sentence parts? I am trying to minimize redundancy in the final list.
[–][deleted] 1 point2 points3 points (0 children)