samedi 5 novembre 2016

python random sampling from list and exporting to txt

I would like to extract several random combinations of strings from a list and store the results in a .csv or .txt

with this code I extract the first combination. Is it possible to add a loop for having 10 extractions and each extractions will be a row in a csv?

import random

items = ['here', 'are', 'some', 'strings', 'of',
         'which', 'we', 'will', 'select', 'one']


rand_items = [items[random.randrange(len(items))]
              for item in range(7)]

print(rand_items)




Aucun commentaire:

Enregistrer un commentaire