Python 从一个大列表中创建更多列表

Python 从一个大列表中创建更多列表,python,python-3.x,list,indexing,split,Python,Python 3.x,List,Indexing,Split,我有下面的列表,它是从我已有的文本文件创建的 最后,我有一个列表,其中包含了我从文本中需要的所有值,现在我试图从列表数组中获得一个以上的小列表,其中每个小列表都以switch开头,以值为空结束 提前感谢 with open("read.txt") as f: for line in f: if line.startswith('switch '): array.append(line) for line in f: # C

我有下面的列表,它是从我已有的文本文件创建的

最后,我有一个列表,其中包含了我从文本中需要的所有值,现在我试图从列表数组中获得一个以上的小列表,其中每个小列表都以switch开头,以值为空结束

提前感谢

with open("read.txt") as f:
    for line in f:
        if line.startswith('switch '):
            array.append(line)
            for line in f:  # Continue iterating f for additional lines to keep
                if not line.rstrip():
                    break  # We hit an empty line, return to looking for switch
                array.append(line)
感谢您的高级

i=0
而我+4