I'm trying to write a python program that asks the user to input lines of text or periods. No numbers and no capital letters/special characters. Each line must be the same length. I want to assign each line to its own list so that I can check for valid words. However, I can't figure out how to make each new line assign to a new list. Everything I write overwrites the previous list. When they hit enter on a blank line, the program will check for valid words across and up and down. I can do that part, but I can't get these lists to assign correctly.
Any help would be appreciated.
Creating a new list every time will be difficult to handle so I suggest you use list of lists. Here is a code snippet which will store the lines in a list of lists. Traversing will be simple as you can index them. The code is given below
count=eval(input("Enter count of lines:")
l=[] #creates a list
i=0
While (i<count):
s=input("Enter line:")
l1=s.split()
l.append(l1)
i+=1
print(l)
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.