user interface - How can I print elements from an imported text file in Python? -


okay, school assignment have been told import txt file , store inside list, have done correctly, , next step print items in 3x3 grid. have come solution doesn't seem working.. here code:

import time import random  words = open("words.txt","r") wordlist = [] lines in words:  wordlist.append(lines) wordlist=[line.rstrip('\n')for line in wordlist]  print(wordlist(0,2)) 

what solution print out 3 @ time list, print position 0, 1 , 2. print 3, 4 , 5 print 6, 7 , 8 , have solution.

try splitting lines list , print list while adding new line every third print, don't append lines wordlist.

words= words.rstrip('\n') wordlist = words.split(" ")  count = 0 word in wordlist:     if count % 3 == 0:         print("\n")     print (word)     count++ 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -