My goal is to have a range of items provide as many outputs as can be had, but without duplicate outputs. The code I've provided is a small sample of what I'm working on. For my larger data set, I notice duplicate outputs plague the CSV file when the script runs so I was wondering if there is a way to keep duplicate outputs from processing while maintaining the high range (100, 250, 400, etc)?
import random
Saying = ["I Like"]
Food = ['Coffee', 'Pineapples', 'Avocado', 'Bacon']
Holiday = ['on the 4th of July', 'on April Fools', 'during Autumn', 'on Christmas']
for x in range(10):
One = random.choice(Saying)
Two = random.choice(Food)
Three = random.choice(Holiday)
print(f'{One} {Two} {Three}')
Thanks for the help!
The issue is that your bot (i guess?) has no memory of what the outputs have been so far, so there's really no way to check with the code you have.
try with this instead:
import random
Saying = ["I Like"]
Food = ['Coffee', 'Pineapples', 'Avocado', 'Bacon']
Holiday = ['on the 4th of July', 'on April Fools', 'during Autumn', 'on Christmas']
memory=[]
done = False
while not done:
One = random.choice(Saying)
Two = random.choice(Food)
Three = random.choice(Holiday)
if f'{One} {Two} {Three}' not in memory:
memory.append(f'{One} {Two} {Three}')
if len(memory) == 10:
done = True
[print(item) for item in memory]
so now instead of taking 10 potshots at creating 10 phrases, we're taking as many as it takes to create 10 different ones.