I have a list of 10 words in words.txt
import random
with open("words.txt") as f:
words = random.sample([x.strip() for x in f], 9)
grouped = [words[i:i+3] for i in range(0, len(words), 3)]
for l in grouped:
print ("").join("{:<10}".format(x) for x in l)
I need to show the list with 9 of the items in the list, and then re print the list with one of the items replaced with the 10th item in the list.
Is this possible. As I show in the code above, I import 9 of the words - each item is on a different line in words.txt.
Aucun commentaire:
Enregistrer un commentaire