mardi 22 août 2017

list not shuffling python

The Code I have here should shuffle the list that contains "ace of hearts" "two of hearts" and "three of hearts".

It retrieves them from the file perfectly well, but it won't shuffle them and simply prints the list twice. As far as I know, a list can include words - however it seems I am mistaken.

import random
def cards_random_shuffle():
    with open('cards.txt') as f:
        cards = [words.strip().split(":") for words in f]
        f.close()
    random.shuffle(cards)
    print(cards)
    return cards




Aucun commentaire:

Enregistrer un commentaire