Python 检查下一行,然后实现该行应该到达的位置

Python 检查下一行,然后实现该行应该到达的位置,python,pseudocode,Python,Pseudocode,我很难弄清楚如何实现一个文本文件,其中的行既有单词行,又有数字行。我想尝试做的是读取单词下面的行,然后将这些单词保存到列表变量中 新的编码,所以请容忍我 示例文本文件: 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 我的伪代码: Open File Read the First Line If the current-line[0]

我很难弄清楚如何实现一个文本文件,其中的行既有单词行,又有数字行。我想尝试做的是读取单词下面的行,然后将这些单词保存到列表变量中

新的编码,所以请容忍我

示例文本文件:

 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
我的伪代码:

 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
我的问题: 如何让python检查下一行,而不离开当前行,然后检查下一行应该转到哪个“if”语句

示例代码:简化

输出:

   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]]

我的伪代码逻辑中的任何帮助都将是非常棒的,或者任何能够提供帮助的东西都将非常感谢。

要阅读下一行,您可以这样做

with open("file.txt", 'r') as f:
    lines = f.readlines()
    current_line_index = 0
    next_line = lines[current_line_index + 1]
    print next_line
下面是我将如何解决这个特殊问题

import csv

word_list = []
number_list = []

with open("file.txt", 'r') as f:
    reader = csv.reader(f)
    for line in reader:
        if line[0].strip().isdigit():
            number_list.append(line)
        else:
            word_list.append(line)

print number_list
print word_list

非常感谢。这很有帮助much@kindall我喜欢编辑!
import csv

word_list = []
number_list = []

with open("file.txt", 'r') as f:
    reader = csv.reader(f)
    for line in reader:
        if line[0].strip().isdigit():
            number_list.append(line)
        else:
            word_list.append(line)

print number_list
print word_list