我有这个文本
/** 早上好
亚历克斯
狗
房子
红色的
*/
/** 晚安
玛丽亚
猫
办公室
绿色的
*/
我想在一个列表中包含Alex、Dog、House 和 red,在另一个列表中包含Maria,Cat,office,green。
我有这个代码
with open(filename) as f :
for i in f:
if i.startswith("/** Goodmorning"):
#add files to list
elif i.startswith("/** Goodnight"):
#add files to other list
那么,有没有什么方法可以编写脚本,以便它可以理解Alex属于具有Goodmorning的文本部分?