dimanche 11 juillet 2021

How do I select multiple elements from a list?

With this code I'm able to select one comment from comments.txt and comment it without repeating itself. How do I select multiple comments at the same time from the comments.txt without the comments repeating themselves?

def random_comment():
    num = randint(1, COMMAND_AMOUNT)
    while num in USED:
        num = randint(1, COMMAND_AMOUNT)
    USED.append(num)
    return COMMENTS[num]    

USED = []
file = open("comments.txt", "r")
COMMENTS = {num: comment.strip() for num, comment in enumerate(file.readlines(), start=1)}
file.close()

COMMAND_AMOUNT = len(COMMENTS)



Aucun commentaire:

Enregistrer un commentaire