Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking next Line to then implement where the line should go to
    primarykey
    data
    text
    <p>I'm having trouble figuring out how to implement having a text file with lines having both lines of words and then lines of numbers. What I want to try and do is read the lines under the words then the saving those words to a list variable.</p> <p>New to coding so bear with me please.</p> <p>Example text File:</p> <pre><code> Hello World 4, 3, 2 3, 4, 2 2, 3, 4 Change the World 5, 3, 9 3, 9, 5 Save the World 1, 2, 3 </code></pre> <p>My Pseudo Code:</p> <pre><code> Open File Read the First Line If the current-line[0] is Letter then: parse the current Line save the parsed to a Word list Go to the next line If the current-line[0] is a Number then: parse the current Line save the parsed line in a list read the next line If the next line has another number then: parse line save it to the previous parsed-line list #Keep Checking if the next line begins with a number #if it doesn't and the next line begins with a letter go back up to the previous statement </code></pre> <p>My question: How can I tell python to check the next line with out leaving my current line and then checking which "if" statement the next line should go to?</p> <p>Example Code: <em>Simplified</em></p> <pre><code> def parse(): return parse txtopen = open("txt","r") line = txtopen.readline() while line: if line[0] is not between 0 or 9:: parse = parse(line) wordlist.append(parse) if line[0] in between 0 and 9: parse = parse(line) list = list.extend(parse) ''' This is where i cant figure out how to read the next line and check ''' finallist = list.append(list) line = txtopen.readline() </code></pre> <p>Output:</p> <pre><code> wordList : ["Hello Word", "Change the World", "Save the World"] numberList : [[4,3,2,3,4,2,2,3,4],[5,3,9,3,9,5],[1,2,3]] </code></pre> <p>Any help within my logic with my pseudo code would be fantastic or anything in general that can help would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload