有人可以帮助我找到将列表扩展到特定索引的另一个列表的方法吗?

问题描述

filenames = ["program.c","stdio.hpp","sample.hpp","a.out","math.hpp","hpp.out"]
new_filename=[]
new_list=[]
final_file=[]
for element in filenames:
    if element.endswith("p"):
        new_filename.append(element)

提取所有以.hpp结尾的文件名 对于new_filename中的element1: new_list.append(element1.split(“ pp”)[0]) 将new_filename中的元素的.hpp转换为.h 对于文件名中的element3: 如果不是,那么element3.endswith(“ p”): final_file.append(element3) 提取非.hpp文件名 final_file.extend(new_list) 打印(最终文件) #应该为[“ program.c”,“ stdio.h”,“ sample.h”,“ a.out”,“ math.h”,“ hpp.out”] #输入中的输出正在获取['program.c','a.out','hpp.out','stdio.h','sample.h','math.h']

# is there any way to extend the new_list to final_file in the index 1 ?

解决方法

关于“将新列表扩展到最终文件”;您可以像这样在某个插入点将列表插入另一个列表:

l1 = ['a','b','c']
l2 = ['x','y','z']

l1[1:1] = l2 # ['a','x','z','c']

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...