This question already has an answer here:
- Python random sample with exception 3 answers
How do I go through a list of 50 names that I have and and pull out 12 at random without any repeats? I can get the names but every once in a while I get duplicates.
files = []
for f in files:
f = random.choice([
x for x in os.listdir(path)
if os.path.isfile(os.path.join(path, x))
])
print(f)
Aucun commentaire:
Enregistrer un commentaire