lundi 3 août 2020

Want to print random strings without repeating one single time

Ok so i want to print random strings but i also want to not be duplicated a single time. i have this code:

import random
howmanytimes=int(input("howmanytimes?:"))

people=int(input("how many people do you want to comment ?:"))

f1=open("comentarios.txt","r")
mentions=random.sample(f1.readlines(),people)
for i in range(howmanytimes):
    print(mentions)

In the document i have a list of names one after the other, however the final result is this:

howmanytimes?:3
how many people do you want to comment ?:2
['@brother\n', '@hehe\n']
['@brother\n', '@hehe\n']
['@brother\n', '@hehe\n'] 

so in this case it prints random but repeats in the following 3 lines, someone can help to give random names in each line ?




Aucun commentaire:

Enregistrer un commentaire