jeudi 25 juillet 2019

Select random filesnames without any repeats [duplicate]

This question already has an answer here:

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