I have a list of 6 words from a text file and would like to open the file to read the list of words as a 3x2 grid, also being able to randomise the order of the words every time the program is run.
words are:
cat, dog, hamster, frog, snail, snake
i want them to display as: (but every time the program is run to do this in a random order)
cat dog hamster
frog snail snake
so far all i've managed to do is get a single word from the list of 6 words to appear in a random order using - help would be much appriciated
import random
words_file = random.choice(open('words.txt', 'r').readlines())
print words_file
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…