list not shuffling python -
the code have here should shuffle list contains "ace of hearts" "two of hearts" , "three of hearts".
it retrieves them file well, won't shuffle them , prints list twice. far know, list can include words - seems mistaken.
import random def cards_random_shuffle(): open('cards.txt') f: cards = [words.strip().split(":") words in f] f.close() random.shuffle(cards) print(cards) return cards
i assume problem loop on lines in file for words in f
when want first line of file.
assuming file looks this:
ace of hearts:two of hearts:three of hearts
then need use first line:
import random def cards_random_shuffle(): open('cards.txt') f: firstline = next(f) cards = firstline.strip().split(':') # alternative read in whole file: # cards = f.read().strip().split(':') print(cards) # original order random.shuffle(cards) print(cards) # new order return cards
wiki
Comments
Post a Comment